Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Duplicate callback outputs #2744

Closed
Liripo opened this issue Feb 5, 2024 · 4 comments
Closed

[BUG] Duplicate callback outputs #2744

Liripo opened this issue Feb 5, 2024 · 4 comments

Comments

@Liripo
Copy link

Liripo commented Feb 5, 2024

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
image

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.

@CNFeffery
Copy link

@Liripo 对于多次出现的Output,其中一个不设置allow_duplicate=True即可,譬如:
image

@Coding-with-Adam
Copy link

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.

@Liripo
Copy link
Author

Liripo commented Feb 29, 2024

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

@CNFeffery
Copy link

@Liripo 我觉得你这几个函数写法本身就很多余,明明是相同的Input()allow_duplicate不应该被滥用,只有在截然不同的Input角色对应重复的Output时才有它的设计意义

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants