Thanks Mccalluc, Great idea.
I implemented your method and I thought id show a simplified example of it.
Please note all the potential problems Mccalluc pointed out.
You can add as many html/dcc components as you want, following the same pattern with the timekeeper divs.
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([
# hidden div for holding timestamp of any DCC or html component
html.Div(id='dcc-timekeeper', children='0', style={'display': 'none'}),
# Any DCC or html item you want to use for ordered trigger
dcc.Dropdown(id='dcc-item',
options=[
{'label': 'Chriddyp', 'value': 'Hr'},
{'label': 'Please notice me', 'value': 'Day'}
],
value='Hr'
),
# 3 buttons to compare to for ease (these can use n_clicks_timestamp like in previous examples)
html.Button(id='btn1',
children='btn1',
n_clicks_timestamp='0'),
html.Button(id='btn2',
children='btn2',
n_clicks_timestamp='0'),
html.Button(id='btn3',
children='btn3',
n_clicks_timestamp='0'),
html.Div(id='results')
])
# use your DCC or html item to trigger a callback to update the dcc-timekeeper div
@app.callback(Output('dcc-timekeeper', 'children'),
[Input('dcc-item', 'value')])
def update_timebase_nclick(value):
return '{}'.format(int(time.time() * 1000))
# use multiple inputs and figure out which one was the trigger as such:
@app.callback(Output('results', 'children'),
[Input('btn1', 'n_clicks_timestamp'),
Input('btn2', 'n_clicks_timestamp'),
Input('btn3', 'n_clicks_timestamp'),
Input('dcc-timekeeper', 'children'),
Input('dcc-item', 'value')])
def slider_buttons(btn1, btn2, btn3, btn4, dccvalue):
if int(btn1) > int(btn2) and int(btn1) > int(btn3) and int(btn1) > int(btn4):
val = 'btn1'
elif int(btn2) > int(btn1) and int(btn2) > int(btn3) and int(btn2) > int(btn4):
val = 'btn2'
elif int(btn3) > int(btn1) and int(btn3) > int(btn2) and int(btn3) > int(btn4):
val = 'btn3'
elif int(btn4) > int(btn1) and int(btn4) > int(btn2) and int(btn4) > int(btn3):
val = 'Dcc item'
return '{}'.format(val)
if __name__ == '__main__':
app.run_server(debug=True)