dash icon indicating copy to clipboard operation
dash copied to clipboard

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

Open jaxonister opened this issue 1 year ago • 5 comments

image

jaxonister avatar Mar 22 '24 09:03 jaxonister

@jaxonister Can you provide code that can reproduce the problem

CNFeffery avatar Mar 23 '24 11:03 CNFeffery

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 avatar Mar 24 '24 03:03 jaxonister

@CNFeffery

jaxonister avatar Mar 24 '24 03:03 jaxonister

@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.

CNFeffery avatar Mar 24 '24 10:03 CNFeffery

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.

Coding-with-Adam avatar Mar 27 '24 14:03 Coding-with-Adam

Closing as we believe this is not a bug.

gvwilson avatar May 31 '24 20:05 gvwilson