The output of the callback functions 1 and 2 is the same. But their inputs are different.
When there is only the first callback function, the callback function works normally.
However, if Iwrite the callback function number 2, both number 1 and number 2 do not work.
Even if I write a code like No. 3, nothing is printed.
I dont konw why this code doesn’t work.
It is not possible to have multiple callback functions updating the same Output. You will need to combine your two callbacks into a single one.
You can use the
import dash_html_components as html
from dash_extensions.enrich import Output, DashProxy, Input, MultiplexerTransform
app = DashProxy(prevent_initial_callbacks=True, transforms=[MultiplexerTransform()])
app.layout = html.Div([html.Button("left", id="left"), html.Button("right", id="right"), html.Div(id="log")])
@app.callback(Output("log", "children"), Input("left", "n_clicks"))
@app.callback(Output("log", "children"), Input("right", "n_clicks"))
if __name__ == '__main__':
Thanks! I solved this problem.
Thank you! It helps me to solve this problem
It’s silly that I can’t have a “reset” button pattern that clears a component’s children just because some other callback created that component’s children. The reset state would have to become an input to the creation callback.
It would be easier to just target the same component property. Conditionally nulling/hiding the different inputs in a monolithic callback creates undue complexity. It leads to [not my post]:
python - A nonexistent object was used in an `Input` of a Dash callback an multipage app - Stack Overflow.
I don’t want 3 separate pages or 3 separate output divs
This feels similar to how:
app.config.supress_callback_exceptions is False by default.
Is preventing multiple callbacks from sharing a common output either: (a) hard-wired into how the callback DAG works, or (b) more of a preventative best-practice-like measure?
Hi @HashRocketSyntax You can find more background information and discussion about this issue in this post: Duplicate Callback Outputs - Solution & API Discussion
@HashRocketSyntax I believe sharing a common ouput between callbacks will be feature of
Dash at some point, but current it is not possible to do directly (it is not just a best practices thing, you’ll get a error if you do it). That being said, the
dash-extensions should cover most cases, so I would recommend using it until a native Dash solution is in place