首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在'app‘中找不到应用程序对象'server’

在'app‘中找不到应用程序对象'server’
EN

Stack Overflow用户
提问于 2018-09-19 06:54:46
回答 1查看 1.3K关注 0票数 7

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

.gitignore

代码语言:javascript
复制
venv
*.pyc
.DS_Store
.env

app.py

代码语言:javascript
复制
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

代码语言:javascript
复制
web: gunicorn app:server

requirements.txt

代码语言:javascript
复制
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

代码语言:javascript
复制
python-3.6.6

我可以在Heroku中成功构建应用程序,但是,由于以下错误消息,我无法正确地为其提供服务:

代码语言:javascript
复制
Failed to find application object 'server' in 'app'

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

EN

回答 1

Stack Overflow用户

发布于 2018-09-19 07:31:27

我在app = dash.Dash()下面添加了:server = app.server

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52395651

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档