使用 plotly 获取 500 Internal server error dash

Getting a 500 Internal server error dash with plotly

我正在尝试使用 python 库 dashplotly 创建仪表板。我已经成功创建了一个静态 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

(与此问题无关):顺便说一下,在命名的 parameters/keyword 参数中不要在 = 周围使用 space 是一个好习惯,这与赋值运算符 =.

例如

random_x = np.random.randint(1, 100, 100) // assignment OK
layout = go.Layout(title = 'bello') // named parameter KO. Should be title='bello'