-
-
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
handle multiple Outputs in app.callback #149
Comments
I second this. This would be incredibly useful. I like the design and look of Dash over alternate programs but the complexity of implementing this is holding me back from fully jumping in. It makes cross-linking multiple plots incredibly difficult compared to Bokeh or Holoviews. |
Makes sense to me! By introducing multiple outputs, there will be 2 ways to do the same thing: 2 outputs in a single callback vs 2 callbacks with a single output. It really only makes to use multiple outputs if the callback is expensive. I can also imagine that some users will end up using multiple outputs in cases where two callbacks that executed in parallel would end up resulting in faster UI updates, for example: @app.callback([Output(...), Output(...)], ...)
def update_outputs(*inputs):
val_1 = expensive_computation_1(*inputs)
output_1 = make_output(val_1)
# if this were a separate callback, the user could return output_1 at this point
# instead, they have lumped together all of the outputs into one function,
# blocking the UI from updating until all outputs are ready
val_2 = expensive_computation_2(*inputs)
output_2 = make_output(val_2)
return [output_1, output_2] In any case, I'm 👍 with this now. It'll be a bit of work to implement, so if you would like to see this work please 👍 this issue. If you or your company needs this work expedited and can sponsor development, please reach out: https://plot.ly/products/consulting-and-oem/ |
btw, as much as Dash is a next-gen framework for full python UI on the browser, you may check APIStar (https://github.com/encode/apistar) that is a next-gen framework for Web API in python (after Django REST Framework, Flask, ...) |
Was this idea ever implemented? I have an app that has 200 buttons. I'd rather append a list of outputs as I make the buttons and pass that to a single callback instead of having to write out 200 callback functions (as this would make my code very long/ugly). |
It hasn't been, but it's still a good idea and I think we'll end up implementing before the end of the year.
What I've done in these types of situations is create a look that generates these functions: def create_callback(id):
def respond_to_button(*callback_args):
...
return respond_to_button
# Dash callbacks have to be defined up-front and therefore must anticipate
# all of the elements that might exist on the page
for i in range(100):
app.callback(
Output('output-{}'.format(i), 'some-property'),
[Input('button-{}'.format(i), 'n_clicks')])(
create_callback(i)) |
Hi @chriddyp, you mentioned the possibility of implementing this "next month" a few weeks ago. Do you have a specific date in mind? |
I do not. I will update this issue when we have a concrete date planned. |
With regards to surface area, it could be a config option, e.g. (I'm currently using |
@chriddyp |
Is there any progress regarding this issue? I would like to start an app with a lot of text field that have to be updated after user interaction. Without multiple updates it would be really a reason to abandon dash due to very complicated and overloaded function usage. |
@cheak1974 It's coming #436 |
I have tried this multiple output but I got an error as Anyone has same issue? |
@prasadovhal You tried the versions in #436 ?
|
Merged - will be in the next release, expected early next week 🎉 |
Is there any update on this? Do we have this feature now? |
Yes! It’s in release :) I’ve been a happy user of this feature for some time |
Check out the "Multiple Outputs" section of https://dash.plot.ly/getting-started-part-2 |
@mkhorton @alexcjohnson Thanks a ton guys for the prompt response. |
How to get 0 outputs but only an eg Interval input? This errors:
i prefer dash clientside over jpnotebooks |
0 outputs doesn't really fit with the dash concept of a stateless back end - that's why it's an error. It's not an error with pattern-matching callbacks that just happen to match zero items, but then the callback won't even fire. If you really want a callback like this to fire I would suggest a dummy element - a hidden div, or a |
* Upgrade plotly.js to v1.33.0 * v0.18.0 * update links
It would be nice to have the ability to update multiple outputs at once by specifying a list of Outputs and returning a tuple with the same number of outputs like in
This would allow simplifying otherwise complex flow to update multiple components based on one change.
The text was updated successfully, but these errors were encountered: