Hi,
After upgrading dash I am seeing some (for me) unexpected behavior. The below code works as intended on 2.9.1. However on >= 2.9.2 I get the following error:
In the callback for output(s):
button.disabled@a8b70adf69db29fef22e63e51b22165f
button.color@a8b70adf69db29fef22e63e51b22165f
Output 1 (button.color@a8b70adf69db29fef22e63e51b22165f) is already in use.
To resolve this, set allow_duplicate=True
on
duplicate outputs, or combine the outputs into
one callback function, distinguishing the trigger
by using dash.callback_context
if necessary.
I simply want a button greyed out and disabled whenever it’s clicked. Basically to make it not spammable.
I noticed there was a change to allow_duplicate in 2.9.2 in the changelog, but I am not dash savvy enough to know why this would affect my example. I hope somebody can come to my rescue!
This is the reproducible code. Try with dash 2.9.1, and then with 2.9.2.
import dash_bootstrap_components as dbc
from dash import html, dash
import time
from dash.dependencies import Input, Output
app = dash.Dash()
app.layout = html.Div([
html.Div([
dbc.Button("Button", id="button", color="danger",
style={"margin-top": "10px"})
], style={"float": "left"})
])
#disable ctc button in modal when clicked
@app.callback(Output("button", "disabled", allow_duplicate=True),
Output("button", "color", allow_duplicate=True),
Input("button", "n_clicks"),
prevent_initial_call=True)
def disable_ctc_button(click):
return [True, "secondary"]
#reenable ctc button after 10 seconds
@app.callback(Output("button", "disabled", allow_duplicate=True),
Output("button", "color", allow_duplicate=True),
Input("button", "n_clicks"),
prevent_initial_call=True)
def reenable_ctc_button(click):
time.sleep(10)
return [False, "danger"]
if __name__ == '__main__':
app.run_server(debug=True)