-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CantHaveMultipleOutputs limit #153
Comments
I'm curious about this too, it seems like it would be quite useful to have multiple callbacks targeting the same property of an element. In fact I think this is going to be quite limiting in some situations. Here for example. I foresee that there could be some confusing scenarios where multiple callbacks are created that target the one output but also share an overlapping input/event, meaning that two callbacks will be triggered and the output element will be updated twice, with the returned value of the one that happens to be handled and received first being clobbered by the second. But this could be detected in the callback validation and the user presented with a warning. I've been looking through the way callbacks are registered in dash.py... would the main issue being having to change the way callbacks are keyed in the callback_map to avoid collisions? The keys could be changed to be the entire callback signature. eg output_element_id--input1_id--input2_id--state1_id--state2_id etc. making them unique Or is there something more fundamental that I'm missing? Edit: Oh I see, you currently need to have already looked up the callback_map to get the information you'd need to reconstruct that signature I proposed... |
Allowing multiple callbacks to share the same output causes too much ambiguity (what happens when there are overlapping inputs?) and violates the zen of python rule "there should be one way to do things". AFAIK, users are only running into the |
The #140 would allow to avoid global variables to get what button has been clicked but it looks still complex to get a basic feature. Specially for buttons, using an Event makes the most sense (vs getting the number of time the button was clicked) but we would need to get a True/False flag parameter representing this event in the callback @app.callback(Output(...), events=[Event('button-id','click')])
def mycb(button_clicked):
# button_clicked is True if the event was fired Or do you see issues with this approach (which is not backward compatible...) |
I think there's two things going on here:
From a pure abstraction point of view, I would want to organise my code like this: model1(text_input1, text_input2) However, in order to target the same Graph element at the moment in Dash, I would need to combine them all into the one callback function and tease apart the different inputs into my different model functions. One of the nice things about Dash is thinking of callbacks as modular functions that correspond to how existing Python functions/abstractions, but we lose that in this case. (Also, all the inputs are going to need to be present in the layout too... so I can't swap them in and together with a callback, I'd have to hide the ones that aren't relevant to the current model) PrevState might help tease apart which inputs were selected, but you still have a bit of a mess regarding the abstractions. |
Regarding the dependencies ambiguities in case of multiple outputs, what happens today in the following case
So when the clock ticks, we would ideally (in some sense of "ideally") compute that:
Should I understand that the logic for dependencies is coded in js ? Could it be possible to adapt this logic to take into account multiple outputs with a "resolution" order that would be based on a "order/priority/z-level" integer argument given in the Output (e.g. |
I ran into the Removing the |
@johnnyheineken have you seen |
Closing - |
@alexcjohnson : Is there any progress on this issue? I know that there was an update regarding dynamic controls, so I am interested whether this issue was adressed as well |
@johnnyheineken Check out https://dash.plotly.com/pattern-matching-callbacks. This lets you connect a callback to a flexible number of inputs and outputs, which can change at any time. |
Is there any update on this? How is the propsed way for updating a |
I often get the CantHaveMultipleOutputs exception due to different callbacks sharing the same output.
This constraint is quite limiting as it requires to refactor quite a bit UI logic that would be simpler if multiple callback could change the same Output.
Is this limit a fundamental limit ? or are they plans to lift this in the coming future ?
The text was updated successfully, but these errors were encountered: