Python Heroku部署:dash.exceptions.NoLayoutException
我试图在Heroku服务器上部署一个多选项卡dash应用程序,但是我得到了一个Python Heroku部署:dash.exceptions.NoLayoutException,python,heroku,plotly,plotly-dash,Python,Heroku,Plotly,Plotly Dash,我试图在Heroku服务器上部署一个多选项卡dash应用程序,但是我得到了一个dash.exceptions.NoLayoutException。以下是构建多页面应用程序的示例: 该应用程序在本地运行良好,我能够使用python index.py和gunicorn index:server命令运行它 我的文件结构如下所示: index.py app.py requirements.txt Procfile Tabs --- Tab1.py --- Tab2.py assets --- style
dash.exceptions.NoLayoutException
。以下是构建多页面应用程序的示例:
该应用程序在本地运行良好,我能够使用python index.py
和gunicorn index:server
命令运行它
我的文件结构如下所示:
index.py
app.py
requirements.txt
Procfile
Tabs
--- Tab1.py
--- Tab2.py
assets
--- style.css
app.py的内容:
import dash
import flask
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
app = dash.Dash(__name__, suppress_callback_exceptions=True)
server = app.server
app = dash.Dash(
meta_tags=[
{"name": "viewport", "content": "width=device-width, initial-scale=1"}
],
external_stylesheets=[dbc.themes.SLATE],
)
index.py的内容
import pandas as pd
import dash
from dash.dependencies import Input, Output, State
import dash_html_components as html
import dash_core_components as dcc
import plotly as py
from plotly import graph_objs as go
from plotly.graph_objs import *
import flask
from app import app
import os
from tabs import reporting, portfolio, market, deal, revenue, comps, analysis
# In[8]:
server = app.server
# App Layout
app.layout = html.Div([
# header
html.Div([
html.H2("Product"),
),
# tabs
html.Div([
dcc.Tabs(
id="tabs",
children=[
dcc.Tab(label="Port", value="p_tab"),
dcc.Tab(label="Leads", value="r_tab"),
],
)
],
className="row tabs_div"
),
# Tab content
html.Div(id="tab_content"),
])
# In[9]:
# Render tabs/subtabs
@app.callback(
Output("tab_content", "children"),
[
Input("tabs", "value"),
Input("subtabs", "value")
],
)
def render_content(tab, subtab):
"""
For user selections, return the relevant tab
"""
if tab == "p_tab":
return tab1.layout
if tab == "r_tab":
return tab2.layout
else:
return (dash.no_update)
# In[10]:
if __name__ == '__main__':
# Production
app.run_server(debug=True)
回溯
2020-08-13T04:23:11.192175097Z app[web.1]: Traceback (most recent call last):
2020-08-13T04:23:11.192180799Z app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
2020-08-13T04:23:11.192185482Z app[web.1]: response = self.full_dispatch_request()
2020-08-13T04:23:11.192189928Z app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1945, in full_dispatch_request
2020-08-13T04:23:11.192194507Z app[web.1]: self.try_trigger_before_first_request_functions()
2020-08-13T04:23:11.192198903Z app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1993, in try_trigger_before_first_request_functions
2020-08-13T04:23:11.192203399Z app[web.1]: func()
2020-08-13T04:23:11.192207530Z app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/dash/dash.py", line 1500, in _setup_server
2020-08-13T04:23:11.192212198Z app[web.1]: self._validate_layout()
2020-08-13T04:23:11.192216422Z app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/dash/dash.py", line 1465, in _validate_layout
2020-08-13T04:23:11.192220923Z app[web.1]: "The layout was `None` "
2020-08-13T04:23:11.192225366Z app[web.1]: dash.exceptions.NoLayoutException: The layout was `None` at the time that `run_server` was called. Make sure to set the `layout` attribute of your application before running the server.
这就是我的工作原理: index.py
从应用程序导入应用程序,服务器
app.py
server=app.server
程序文件
web: gunicorn index:server
显然,您链接到的多应用程序示例,即官方Dash文档中的示例,有一个错误。Gunicorn不接受语法,
:。
。此论坛帖子向我指出了此解决方案:
这就是我的工作原理: index.py
从应用程序导入应用程序,服务器
app.py
server=app.server
程序文件
web: gunicorn index:server
显然,您链接到的多应用程序示例,即官方Dash文档中的示例,有一个错误。Gunicorn不接受语法,
:。
。此论坛帖子向我指出了此解决方案:
尝试将procfile更改为
gunicorn index:app.server
这解决了问题。我也有同样的问题。我已将所有内容更改为上面的示例,但当我运行gunicorn index:app.server时,我得到“无法将'app.server'解析为属性名称或函数调用”。请确保它是web:gunicorn index:app.server
尝试将procfile更改为gunicorn index:app.server
这解决了问题。我也有同样的问题。我已将所有内容更改为与上面的示例类似,但当我运行gunicorn index:app.server时,我得到“无法将'app.server'解析为属性名称或函数调用”。请确保它是web:gunicorn index:app.server