I’ve multiple celery background callbacks running in parallel. I’d like to cancel all of them by single button cancel=Input("cancel_processing_button_id", "n_clicks"),
however this leads to (surprisingly) duplicated Outputs error:
In the callback for output(s):
cancel_processing_button_id.id
Output 0 (cancel_processing_button_id.id) 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.
Any ideas what is wrong would be appreciated.
Thanks!
I guess it is because Dash internally creates a callbacks, which has this component as Output. Hence, for each similar repeat, a new such callback is created, thus leading to multiple callbacks that targets the same Output. Ideally for your use case, these callbacks should be changed in the source to include allow_duplicate flags. Until that happens, you should be able to monkey patch your way out by placing code like,
Thanks @Emil for your hint.
I’ve decided to go with separate cancel button per background callback for now. Though it would be nice to have that implemented properly one day.
One more observation: cancel /running actions of background callbacks seem not to work with compound ids (dicts) e.g. id={'role': 'cancel_processing', 'task': task} however they work fine when using plain strings id=f'cancel_processing_{task}'