Hi All
Problem
I have recently been confronted to the following issue with Dash:

I have two callbacks which point to the same output curve_type_selection. Here is the code:
@callback(
Output("graph", "figure"),
Output("curve_type_selection", "disabled", allow_duplicate=True),
Output("wait_completion", "children"),
Input("curve_type_selection", "value"),
State("url", "pathname"),
State("graph", "figure"),
prevent_initial_call=True,
)
def draw_parametric_curve(selected_curve, pathname, figure):
"""Callback function to trigger the computation."""
project = DashClient[Cosmic_WaveSolution].get_project(pathname)
step = project.steps.compute_step
step.selected_curve = selected_curve
step.compute_parametric_curve()
figure["data"][0]["x"] = step.x_coords
figure["data"][0]["y"] = step.y_coords
return figure, False, True
@callback(
Output("curve_type_selection", "disabled", allow_duplicate=True),
Input("curve_type_selection", "value"),
prevent_initial_call=True,
)
def disable_selection(selected_curve):
"""Callback function to trigger the computation."""
return True
I added the allow_duplicate option to get ride of the duplicate outputs error as recommended in Dash documentation. But still I am getting the error message.
Solution
The solution can be found here. The issue was actually not with the outputs, but rather with the inputs. The workaround is to either switch the orders of the inputs wherever possible, or add a dummy input wherever necessary.
In my case, I added a dummy input like this:
@callback(
Output("graph", "figure"),
Output("curve_type_selection", "disabled", allow_duplicate=True),
Output("wait_completion", "children"),
Input("curve_type_selection", "n_clicks"), # Dummy input to avoid callbacks outputs duplicates
Input("curve_type_selection", "value"),
State("url", "pathname"),
State("graph", "figure"),
prevent_initial_call=True,
)
def draw_parametric_curve(n_click, selected_curve, pathname, figure):
"""Callback function to trigger the computation."""
ctx = callback_context
if "curve_type_selection.value" in ctx.triggered_prop_ids.keys():
project = DashClient[Cosmic_WaveSolution].get_project(pathname)
step = project.steps.compute_step
step.selected_curve = selected_curve
step.compute_parametric_curve()
figure["data"][0]["x"] = step.x_coords
figure["data"][0]["y"] = step.y_coords
return figure, False, True
raise PreventUpdate
@callback(
Output("curve_type_selection", "disabled", allow_duplicate=True),
Input("curve_type_selection", "value"),
prevent_initial_call=True,
)
def disable_selection(selected_curve):
"""Callback function to trigger the computation."""
return True