Two buttons updating the same output with two callbacks doesn't work
spooseh opened this issue · comments
Sorry if I miss something trivial; I'm new to Dash. I need to update one object from different stages of a complicated app. Here is an example where a single output is supposed to be updated by two different buttons. With this code, only one button, the one which appears last in the code ("b2" here), modifies the output. I could solve this using callback_context() and just one callback but having two separate callbacks is preferable, if possible.
using Dash
app = dash()
callback!(app, Output("output", "children"), Input("b1", "n_clicks")) do nc
msg = "No clicks!";
if nc > 0
msg = "B1, $nc times!";
end
return html_h5(msg)
end
callback!(app, Output("output", "children"), Input("b2", "n_clicks")) do nc
msg = "No clicks!";
if nc > 0
msg = "B2 , $nc times!"
end
return html_h5(msg)
end
app.layout = html_div([
html_hr(),
html_button("Button1", id="b1", n_clicks=0),
html_hr(),
html_div(id="output"),
html_hr(),
html_button("Button2", id="b2", n_clicks=0),
])
run_server(app, "0.0.0.0", 8888)
Yes, callback_context
is the solution - two separate callbacks leads to ambiguous behavior in some circumstances.