-
-
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
[Feature Request] simplified syntax when several Inputs can trigger a callback #1054
Comments
I am considering making an attempt to implement a
What do you think about this kind of syntax? I made a demo implementation in https://pypi.org/project/dash-extensions/ The problem about "unwrapping the trigger" being cumbersome could be (at least partly) solved by introducing a utility function, similar to |
That works if there's only one input - though in that case the existing |
Multiple triggers (and triggers mixed with inputs) is supported. The only difference (in my current implementation) between trigger and inputs is that the argument (‘n_clicks’) is not passed to the function for s trigger, i.e. you still have to figur out which trigger/input triggered the callback. |
We ended up deciding |
With Dash, it is not possible to have multiple callbacks modifying a given
Output
(see #153). The reason is that if this were possible, one could imagine having several callback sharing as Input the same property and modifying the sameOutput
, and one could not decide which one to fire.Therefore, the solution is to group all the inputs in a big callback, and since a different behaviour is often expected depending on which
Input
fired the callback, one ends up with a quite verbose syntax such as@alexcjohnson suggested that we could introduce a
Trigger
object which would be a variant ofInput
. It would be called asTrigger("button1", "n_clicks")
and would feed the callback True (if that was the trigger) or False. Therefore we could write callbacks likeAs a side note it would be great to update our documentation to encourage more breaking callbacks into smaller functions like above, so that a multiple-input callback is more a router.
A variant of the
Trigger
would be to have a tuple(triggered_bool, prop_value)
so that one would writearg1_changed[0]
for the bool andarg1_changed[1]
for the value. (Therefore we would not need to usecallback_context
at all).The text was updated successfully, but these errors were encountered: