heroku - 在“应用程序”中找不到应用程序对象“服务器”
问题描述
我正在尝试使用 Heroku 提供 Dash 应用程序。我的应用程序中有 5 个文件:
.gitignore
venv
*.pyc
.DS_Store
.env
应用程序.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)
档案
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()
推荐阅读
- spring - 如何从java中的属性文件中按值读取特定键
- spring - 如何更改弹簧资源列表名称
- git - IntelliJ 合并显示没有内容
- python - 计算两列给定值的天数差异
- html - 如果没有 href 属性,则保留锚样式
- javascript - 我在使 istrusted 事件为 true 以单击网页时遇到问题。我正在使用 chrome 扩展程序单击
- ios - NSLayoutContraints:如何将底部视图定位在两个标签中较高者的下方?
- javascript - 如何在 Angular 应用程序中从 YAML 文件(保存在我的 PC 中)读取数据?
- php - 如何仅使用 tcp/ip 将 sql-Dump 上传到远程数据库服务器
- php - 确保最新数据在 SQL 查询中优先