I have many callback functions that are supposed to generate a figure. However, sometimes they fail, so I included a try-except mechanism to catch the error and show it to the user as Modal, something like this
@callback(
[Output("fig", "figure"),
Output("error-message", "children"),
Output("error-modal", "is_open")],
Input("submit", "n_clicks"),
State("locations-list", "data"))
)
def generate_figure(n_clicks):
if n_clicks is None:
return make_empty_figure(), None, False
try:
data = get_data()
return make_figure(data), None, False
except Exception as e:
return make_empty_figure(), repr(e), True
This works only with 1 function.
As soon as I try to use the same mechanism with different functions I get the error Output 2 (error-modal.is_open) is already in use.
, probably because the same Output is used in multiple callbacks.
I think this is happening when the application is loading.
As I don’t want to update the Modal at this time I tried using no_update
in place of None
and False
without luck. I also tried to prevent the initial call of all these callbacks, adding the allow_duplicate
option but I still get this error.
So, how can I trigger the same modal from different callback functions without having this error?