[BUG] Duplicate callback outputs
Liripo opened this issue · comments
Hello:
I tried using the same Input
, but there are some differences in the Output
, but dash prompts me that I need to increase allow_duplicate = True
。
example dash:
from dash import Dash, html,callback,Output,Input,no_update
app = Dash(__name__)
app.layout = html.Div([
html.Div(children='output1',id="output1"),
html.Div(children='output2',id="output2"),
html.Button("button",id = "button")
])
@callback(
Output("output1","children",allow_duplicate=True),
Input("button","n_clicks"),
prevent_initial_call=True,
)
def out1(n_clicks):
return no_update
@callback(
Output("output1","children",allow_duplicate=True),
Output("output2","children"),
Input("button","n_clicks"),
prevent_initial_call=True,
)
def out2(n_clicks):
return no_update,no_update
if __name__ == '__main__':
app.run(debug=True)
If I change one of the Output
parameters to allow_duplicate=False
, no error is reported.
Thanks.
hi @Liripo
I'm not getting the error that you are getting.
But @CNFeffery 's code is appropriate. Technically, only the second callback is the duplicate, so you only need to add allow_duplicate=True
there.
If I increase it to 3, it has error.
from dash import Dash, html,callback,Output,Input,no_update
app = Dash(__name__)
app.layout = html.Div([
html.Div(children='output1',id="output1"),
html.Div(children='output2',id="output2"),
html.Div(children='output3',id="output3"),
html.Button("button",id = "button")
])
@callback(
Output("output1","children"),
Input("button","n_clicks"),
)
def out1(n_clicks):
return no_update
@callback(
Output("output1","children",allow_duplicate=True),
Output("output2","children"),
Input("button","n_clicks"),
prevent_initial_call=True,
)
def out2(n_clicks):
return no_update,no_update
@callback(
Output("output1","children",allow_duplicate=True),
Output("output3","children"),
Input("button","n_clicks"),
prevent_initial_call=True,
)
def out3(n_clicks):
return no_update,no_update
if __name__ == '__main__':
app.run(debug=True)
I think maybe it's a bug. @Coding-with-Adam