I have a loading dialog that prompts to the user while the data is being loaded. I can easily show it when the user clicks a button, but I also need an easy way to hide it when the data is loaded.
I was thinking that I nice way to address it it would be to have a callback that listens to an event (a signal) and hides the dialog when this event is received. The last piece I need to finish my puzzle it would be to have a way to trigger a Dash event that a callback can listen to directly from my Python code.
I have been looking in the documentation and in the forums, but I haven’t found any way to trigger this kind of events.
As a workaround, I could use a hidden div and use it as a trigger for hiding the dialog. But the other way looks like a more convenient way to me; moreover, I think the potential of Dash could be enlarger provided with this capability.
The most generic solution to this is going to be per-component loading states, as discussed in 📣 Dash Loading States. This is a big project, and we’re looking for companies or organizations to help sponsor the work (Consulting, Training & Open-Source Development).
Another alternative is to build your own component (Build Your Own Components | Dash for Python Documentation | Plotly) that provides properties / attributes that represent the different stages of this component (“loading”, “done_loading”, etc).
The most generic solution to this is going to be per-component loading states, as discussed in Dash Loading States.
Awesome. This really suits our needs, although we are still looking for a way to discretionally trigger callbacks from Python code.
This is a big project, and we’re looking for companies or organizations to help sponsor the work (http://plot.ly/products/consulting-and-oem).
We will consider it. Thank you.
Another alternative is to build your own component (https://plot.ly/dash/plugins1) that provides properties / attributes that represent the different stages of this component (“loading”, “done_loading”, etc).
I’ve already done that, here is our loading react component: https://github.com/Grasia/grasia-dash-components/blob/master/src/components/LoadingDialog.react.js But we’re looking for a way to integrate with the official dash-renderer repo (see opened issue).
Going back to the topic thread, would you be willing to merge a pull request that allows to trigger dash Events from python code? I think that it isn’t a big work, am I right?
Right now, Dash uses regular HTTP requests, not websockets, so the event has to “originate” from the browser. So, even if you were to able to call the Python function in Python, we don’t have a way to propagate that update to the dash front-end. In the future, if we ever add websocket support, this would be possible.
possible, server side events might be of interest here. this bypasses the need for websockets, allowing for the existing mechanisms in place to provide pushing to the browser.
This is both very doable with generators, a interesting implementation based on
redis also exists.
Any progress on this? Especially based on the last comment.
No progress on this, and this isn’t currently scheduled for the next few months. We’re focusing on a few other things for the short term: Projects · plotly · GitHub
I see, well, fingers crossed to see it at some point. Still, the changes over the past few months have been great already!
And, follow-up question: I could try to workaround using events, because I don’t want to handle too many inputs. What are the events associated with dcc.Dropdown and dcc.Input? I only want to register ‘user makes a change’ or ‘user interacts’. Is there a doc somewhere?
There isn’t really. I"m actually trying to move away from
Event, as it isn’t quite the right abstraction (it’s not possible to tell _which_event was fired, which makes it unuseful and confusing). Instead, I recommend using
Input to trigger your change. If you don’t want to handle as many inputs in the callback, just place them at the end and use
@app.callback(Output(...), [Input(...), Input(...), Input(...), ...])
def update(value1, value2, *args)
If I understood the comment by @_jf correctly, it should somehow be possible to use Server-Sent-Events to “Live-Update” the Dash-Dashboard, right? This would be pretty helpful, as I currently have a Prediction-Service in the back-end which I want to use to publish new predictions.
I had a look at the Medium-Post, but I am not sure if and how this could be integrated within Dash? Do you guys know any further resources on how to implement SSE such that the Dash-Interface is getting updates from the prediction-service?
Thank you in advance and happy holidays everyone!