I am reading about the first example on https://dash.plot.ly/dash-core-components/store
why
@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)
instead of
@app.callback(Output('{}-clicks'.format(store), 'children'),
[Input(store, 'data')])
def on_data(data):
data = data or {}
return data.get('clicks', 0)
I don't understand the reason for using modified_timestamp
.
From the docs page you shared:
Retrieving the initial store data
If you use the data prop as an output, you cannot get the initial data on load with the data prop. To counter this, you can use the
modified_timestamp
as Input and the data as State.This limitation is due to the initial None callbacks blocking the true data callback in the request queue.
See https://github.com/plotly/dash-renderer/pull/81 for further discussion.