Plotly Dash 错误加载布局

Plotly Dash Error loading layout

嗨,我是 Dash 的新手,我正在按照页面上的教程进行操作 https://dash.plot.ly/getting-started 我收到一条错误消息,指出未安装 msgpack。我稍后安装了它,然后运行页面上给出的以下代码。

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A Web Application framework for Python.
        '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data':[
                {'x':[1,2,3],'y':[2,4,1],'type':'bar','name':'SF'}
            ],
            'layout': {
                'title':'Dash Data Visualisation'
            }
        }
    )
])

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

当我继续这个 http://127.0.0.1:8050/ 我得到以下错误

Error loading layout

我阅读了 dash 文档和社区帮助,有一些类似的问题被问到,但我无法理解它们。请帮忙。

当我在终端中 运行 时,code 工作正常。 link 显示了 bar plot(下图)。可能是您的 dash 安装缺少一些 libraries / requirement 文件。您可以尝试从终端执行 pip installconda install 下面列出的包。

有关如何使用 pip

安装的示例
$ pip install <package name here>

或者如果使用 Ananconda

$ conda install <package name here>

示例:

$ pip install chardet==3.0.4

chardet==3.0.4
click==6.7
Cython==0.28.2
dash==0.21.0
dash-core-components==0.22.1
dash-html-components==0.10.0
dash-renderer==0.12.1
decorator==4.3.0
nbformat==4.4.0
numpy==1.14.2
pandas==0.22.0
pandas-datareader==0.6.0
plotly==2.5.1
python-dateutil==2.7.2
pytz==2018.4
requests==2.18.4
urllib3==1.22
Werkzeug==0.14.1

编辑 - 1 ................................... ....

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()
app.layout = html.Div(children=[html.H1(children='Hello Dash')])
if __name__ == '__main__':
    app.run_server(debug=True)

post 的基础上添加以下行进行导入。

import dash
import dash_core_components as dcc
import dash_html_components as html
from dashapp import app as application

app = dash.Dash()
app.layout = html.Div(children=[html.H1(children='Hello Dash')])
if __name__ == '__main__':
    app.run_server(debug=True)

import dash
import dash_core_components as dcc
import dash_html_components as html
from dashapp import server as application

app = dash.Dash()
app.layout = html.Div(children=[html.H1(children='Hello Dash')])
if __name__ == '__main__':
    app.run_server(debug=True)

import dash
import dash_core_components as dcc
import dash_html_components as html
from dashapp import server as application

app = dash.Dash()
app.layout = html.Div(children=[html.H1(children='Hello Dash')])
if __name__ == '__main__':
    app.run_server(debug=True)

from dashapp import server as application

and/or 更改以下任一项 [post]:

app = Dash()
app = dash.Dash(__name__)
server = app.server

编辑 - 2 ................................... ....

Install dash libraries

pip install dash==0.21.1  # The core dash backend
pip install dash-renderer==0.13.0  # The dash front-end
pip install dash-html-components==0.11.0  # HTML components
pip install dash-core-components==0.24.0  # Supercharged components
pip install plotly --upgrade  # Latest Plotly graphing library

also

pip install dash.ly --upgrade

我再次删除了所有库并重新安装它们以及 运行 Chrome 中的代码。现在工作正常。

我也是 Dash 的新手,就我而言,语法有问题。

我是这样做的:

app.layout = html.Div({

并且正在获取“错误加载布局”

但是当我切换到这个时:

app.layout = html.Div(children=[

错误消失了。

检查主要 Div 的语法是否有任何错误。

在较旧的 shinyproxy 版本中使用破折号时,您会遇到同样的错误。由于搜索会将您重定向到此 post 我也将答案放在这里。

使用

app.config.update({
'routes_pathname_prefix': os.environ['SHINYPROXY_PUBLIC_PATH'],
'requests_pathname_prefix': os.environ['SHINYPROXY_PUBLIC_PATH']
})

如图here and discussed here