dash
dash copied to clipboard
When there are three identical outputs, the allow_duplicate is set and an error will be reported.
@jaxonister Can you provide code that can reproduce the problem
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)
@CNFeffery
@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.
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.
Closing as we believe this is not a bug.