我正在阅读关于https://dash.plot.ly/dash-core-components/store的第一个例子
为什么
@app.callback(Output('{}-clicks'.format(store), 'children'),
[Input(store, 'modified_timestamp')],
[State(store, 'data')])
def on_data(ts, data):
if ts is None:
raise PreventUpdate
data = data or {}
return data.get('clicks', 0)
代替
@app.callback(Output('{}-clicks'.format(store), 'children'),
[Input(store, 'data')])
def on_data(data):
data = data or {}
return data.get('clicks', 0)
我不明白使用modified_timestamp
的原因。
在您分享的文档页面中:
检索初始商店数据
如果使用数据prop作为输出,则无法使用数据prop获取初始数据。为了解决这个问题,您可以使用
modified_timestamp
作为输入,将数据用作State。此限制是由于初始None回调阻塞了请求队列中的真实数据回调。
有关进一步的讨论,请参阅https://github.com/plotly/dash-renderer/pull/81。