How can I write a callback such that if button 1 is clicked, do A; if button 2 is clicked, do B; if a dropdown value is changed, do C?
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash(__name__)
app.layout = html.Div([
html.H1('initial', id = 'h1'),
html.Button('to upper', id = 'upper button', n_clicks_timestamp = '0'),
html.Button('to lower', id = 'lower button', n_clicks_timestamp = '0'),
dcc.Dropdown(options = [{'value':s, 'label': s} for s in ['good','bad']], value = 'good', id = 'set string')
])
@app.callback(
dash.dependencies.Output('h1', 'children'),
[dash.dependencies.Input('upper button', 'n_clicks_timestamp'),
dash.dependencies.Input('lower button', 'n_clicks_timestamp'),
dash.dependencies.Input('set string', 'value')],
[dash.dependencies.State('h1', 'children')]
)
def update(upper, lower, newstring, currentstring):
upper, lower = int(upper), int(lower)
# ???
# if dropdown changed, return newstring
# ???
if upper > lower:
return currentstring.upper()
if lower > upper:
return currentstring.lower()
return newstring
if __name__ == '__main__':
app.run_server(debug=False)
Since the dropdown doesn't have a timestamp property, there is no way to decide if it is the latest change.