我正在尝试使用python库dash
和plotly
创建仪表板。我已经成功创建了一个静态html仪表板,但是当我尝试添加绘图图而不是纯html时,我得到了500 Internal Server Error
。我的代码如下:
import dash
import dash_html_components as html
import dash_core_components as dcc
import plotly.graph_objs as go
import numpy as np
app = dash.Dash()
# Creating data
np.random.seed(42)
random_x = np.random.randint(1, 100, 100)
random_y = np.random.randint(1, 100, 100)
data = [go.Trace(
x = random_x,
y = random_y,
mode = 'lines'
)]
layout = go.Layout(title = 'bello')
app.lyaout = html.Div([dcc.Graph(id = 'lineplot', figure = {'data': data, 'layout': layout})])
if __name__ == '__main__':
app.run_server()
[这在我尝试访问网页时输出:
raise exceptions.NoLayoutException(
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.
非常感谢您的帮助!
[我猜您已经知道了,这只是第24行的错字错误。应该是app.layout
而不是app.lyaout
。
((与该问题无关):顺便说一句,与赋值运算符=
不同,在命名参数/关键字参数中的=
周围不留空格是一个好习惯。
例如
random_x = np.random.randint(1, 100, 100) // assignment OK
layout = go.Layout(title = 'bello') // named parameter KO. Should be title='bello'