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

When there are three identical outputs, the allow_duplicate is set and an error will be reported. #2810

Open
jaxonister opened this issue Mar 22, 2024 · 5 comments

Comments

@jaxonister
Copy link

image

@CNFeffery
Copy link

@jaxonister Can you provide code that can reproduce the problem

@jaxonister
Copy link
Author

import dash
from dash import html
import feffery_antd_components as fac
from dash.dependencies import Input, Output

app = dash.Dash(__name__)

app.layout = html.Div(
    [
        fac.AntdSpace(
            [
                fac.AntdButton(
                    '按钮1',
                    id='button-demo1'
                ),
                fac.AntdButton(
                    '按钮2',
                    id='button-demo2'
                )
            ]
        ),
        fac.AntdParagraph(
            id='output-demo'
        )
    ],
    style={
        'padding': '50px 100px'
    }
)


@app.callback(
    Output('output-demo', 'children'),
    Input('button-demo1', 'nClicks'),
    prevent_initial_call=True
)
def trigger1(nClicks):
    return f'按钮1: {nClicks}'


@app.callback(
    Output('output-demo', 'children', allow_duplicate=True),
    Input('button-demo1', 'nClicks'),
    prevent_initial_call=True
)
def trigger2(nClicks):
    return f'按钮2: {nClicks}'


@app.callback(
    Output('output-demo', 'children', allow_duplicate=True),
    Input('button-demo1', 'nClicks'),
    prevent_initial_call=True
)
def trigger3(nClicks):
    return f'按钮3: {nClicks}'


if __name__ == '__main__':
    app.run(debug=True)

@jaxonister
Copy link
Author

@CNFeffery

@CNFeffery
Copy link

@jaxonister I believe that the significance of the allow_duplicate parameter in Dash pertains to the support for updating the same Output under different Input contexts. However, your code has completely replicated both the Input and Output roles. It is advisable that you prioritize the optimization of callback orchestration rather than treating allow_duplicate as a panacea that can be liberally applied.

@Coding-with-Adam
Copy link

Thanks for your support @CNFeffery. I think it's because the Input is repeated 3 times. If there is only 2 repetitions of an Input, it works.

@jaxonister is there a reason you need to repeat the Input three times. I'm not sure why one would want the exact same callback three times? Also, these type of questions are best asked on the Plotly forum. Given the size of the community, you're likely to get an answer quicker.

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

No branches or pull requests

3 participants