我正在使用Dash - Plot.ly创建仪表板,并且需要定期更新。我找到了应该完成这项工作的dcc.Interval()
组件,但是发生了一种奇怪的行为。在代码正确的情况下,回调只被调用一次,如果代码中有错误,比如引用了不存在的变量,循环行为就会出现。你知道哪里出了问题吗?
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly
from dash.dependencies import Input, Output
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout=html.Div([dcc.Interval(id='interval-component',
interval=1*1000, n_intervals=0)], id="acoolId")
@app.callback(
Output('acoolId', 'children'),
[Input('interval-component', 'n_intervals')])
def timer(n):
# print(asdlol) # if this line is enabled, the periodic behavior happens
return [html.P("ASD " + str(n))]
if __name__ == '__main__':
app.run_server(debug=True)
https://stackoverflow.com/questions/56278912
复制相似问题