无法在“app”中找到应用程序对象“服务器”

2024-04-21

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

.gitignore

venv
*.pyc
.DS_Store
.env

app.py

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

要求.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

运行时.txt

python-3.6.6

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

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

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


我补充道:server = app.server就在下面app = dash.Dash()

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在“app”中找到应用程序对象“服务器” 的相关文章

随机推荐