无法在'app'中找到应用程序对象'server'

问题描述 投票:2回答:1

我正在尝试使用Heroku提供Dash应用程序。我的应用中有5个文件:

的.gitignore

venv
*.pyc
.DS_Store
.env

app.朋友

import os

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import pandas as pd

# Read in the data
districts_change = pd.read_csv("https://github.com/thedatasleuth/New-York-Congressional-Districts/blob/master/districts_change.csv?raw=True")

df = districts_change.drop(['TOTAL'], axis=1)

# Get a list of all the districts
districts = districts_change['DISTRICT'].unique()

# Create the app
app = dash.Dash()

# Populate the layout with HTML and graph components
app.layout = html.Div([
    html.H2("New York Congressional Districts"),
    html.Div(
        [
            dcc.Dropdown(
                id="DISTRICT",
                options=[{
                    'label': 'District {}'.format(i),
                    'value': i
                } for i in districts],
                value='All Districts'),
        ],
        style={'width': '25%',
               'display': 'inline-block'}),
    dcc.Graph(id='funnel-graph'),
])


# Add the callbacks to support the interactive componets
@app.callback(
    dash.dependencies.Output('funnel-graph', 'figure'),
    [dash.dependencies.Input('DISTRICT', 'value')])
def update_graph(Districts):
    if Districts == "All Districts":
        df_plot = df.copy()
    else:
        df_plot = df[df['DISTRICT'] == Districts]

    trace1 = go.Bar(x=df_plot ['Year'], y=df_plot [('DEM')], name='DEM')
    trace2 = go.Bar(x=df_plot ['Year'], y=df_plot [('REP')], name='REP')
    trace3 = go.Bar(x=df_plot ['Year'], y=df_plot [('CON')], name='CON')
    trace4 = go.Bar(x=df_plot ['Year'], y=df_plot [('WOR')], name='WOR')
    trace5 = go.Bar(x=df_plot ['Year'], y=df_plot [('IND')], name='IND')
    trace6 = go.Bar(x=df_plot ['Year'], y=df_plot [('GRE')], name='GRE')
    trace7 = go.Bar(x=df_plot ['Year'], y=df_plot [('WEP')], name='WEP')
    trace8 = go.Bar(x=df_plot ['Year'], y=df_plot [('REF')], name='REF')
    trace9 = go.Bar(x=df_plot ['Year'], y=df_plot [('OTH')], name='OTH')
    trace10 = go.Bar(x=df_plot ['Year'], y=df_plot [('BLANK')], name='BLANK')


    return {
        'data': [trace1, trace2, trace3, trace4, trace5,
                     trace6, trace7, trace8, trace9, trace10],
        'layout':
        go.Layout(
            title='District {}'.format(Districts),
            barmode='group')
    }


if __name__ == '__main__':
    app.server.run(debug=True)

Procfile

web: gunicorn app:server

requirements.txt

Flask==1.0.2
gunicorn==19.9.0
dash==0.26.5
dash-core-components==0.29.0
dash-html-components==0.12.0
dash-renderer==0.13.2
plotly==3.2.1
pandas==0.23.1
pandas-datareader==0.6.0

runtime.txt

python-3.6.6

我能够在Heroku中成功构建应用程序,但是,由于此错误消息,我无法正确地提供它:

Failed to find application object 'server' in 'app'

它在说什么服务器?通常当我收到此错误时,我只需要将任何缺少的内容添加到requirements.txt文件中。

heroku plotly-dash
1个回答
2
投票

我补充说:server = app.server正好在app = dash.Dash()

© www.soinside.com 2019 - 2024. All rights reserved.