Hi,
The store component in dash (dcc.Store) has attribute modified_timestamp
but is there a way to know when store component is updated, even when data remains the same?
I tried to use the code below, which gets the timestamp in dcc-timekeeper
. However, it seems that when updating the store component, other callbacks are not working. I expect that after selecting a value in dropdown, and then click the button, it should return ‘button is clicked’. But there’s no response.
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import time
app = dash.Dash()
app.layout = html.Div([
html.Div(id='dcc-timekeeper', children='0', style={'display': 'none'}),
dcc.Store(id='intermediate', modified_timestamp=0),
dcc.Dropdown(id='dcc-item',
options=[
{'label': 'AAAAA', 'value': 'AAAAA'},
{'label': 'BBBBB', 'value': 'BBBBB'}
],
value='AAAAA'
),
html.Button(id='button',
children='button',
n_clicks_timestamp='0'),
html.Div(id='results')
])
@app.callback(
Output('intermediate', 'data'),
[Input('dcc-item', 'value')]
)
def update_in(value):
time.sleep(10)
return 'data'
@app.callback(Output('dcc-timekeeper', 'children'),
[Input('intermediate', 'data')])
def update_timebase_nclick(value):
return '{}'.format(int(time.time() * 1000))
@app.callback(Output('results', 'children'),
[Input('button', 'n_clicks_timestamp'),
Input('dcc-timekeeper', 'children')])
def slider_buttons(button, dcc):
if int(button)>int(dcc):
val = 'button is clicked'
else:
val = 'dcc.Store value updated'
return val
if __name__ == '__main__':
app.run_server(debug=True)
Would really appreciate any help!