您好,我是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
我阅读了破折号文档和社区帮助,也有一些类似的问题,但我听不懂。请帮忙。
答案 0 :(得分:1)
code
在终端中运行时工作正常。链接显示了bar plot
(在下面)。可能是您的dash
安装中缺少一些libraries
/ requirement
文件。您可以尝试从终端执行以下列出的pip install
或conda 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
和/或更改以下任一 [post]:
app = Dash()
app = dash.Dash(__name__)
server = app.server
编辑-2 ..................................................
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
答案 1 :(得分:0)
我再次删除了所有库并重新安装它们,并在Chrome中运行了代码。现在工作正常。
答案 2 :(得分:0)
我也是 Dash 的新手,就我而言,语法有问题。
我是这样做的:
app.layout = html.Div({
并且得到“错误加载布局”
但是当我切换到这个时:
app.layout = html.Div(children=[
错误消失了。
检查主 Div 的语法是否有任何错误。