Triggering callback from within Python

#1

Hello,

I’m working with Dash as a really nice way to interact with an embedded system. One thing I keep running into is the need to generate a callback from within the Python code, outside of callback code.

For example, I’m using a progress indicator html component to indicate progress of saving a file. I can update the progress component from within an interval callback, and that works, but it would be more natural to generate a property change from within my Python code – such as:

#  change 'value' property of 'save-progress' indicator -- set it to progVal

dcc.sendOutput('save-progress', 'value', progVal)  

I mostly bring it up because it seems like a way to simplify other parts of my interface as well. I have more examples… but for starters, I’m wondering if there is another way to accomplish this, or if something like this has been discussed before.

FWIW I’m using socketIO (websockets) for a custom video streaming Dash component. It’s given me enough confidence to consider digging in parts of Dash that I have no business digging into.

I may be barking up the wrong tree… let me know :)

thanks!

#2

Just looking for a quick “sounds reasonable” or “this is a bad idea” or “this make no sense” :slight_smile: gracias

#3

I’m not a Dash developer but my understanding of the architecture of the library is all initial calls are made from the JavaScript using classical AJAX-style calls, and therefore it’s all request from browser response from server.

I’m sure it would be possible to re-architect it to have a bi-directional communication using newer web communication technologies, but I’ve not heard anything from the Dash developers that indicate they are working on this. Maybe you could code your own component to do this but I don’t know enough about React to know if it’s reasonable: https://dash.plot.ly/plugins

Also be aware they accept funding from enterprises to push Dash forward and if those enterprises are anything like the one I work for they insist everything must work in IE 11 :slightly_frowning_face:

#4

thanks!

There have been mentions of websockets in these forums and dispatch emails – never in the “it will happen” context though. Browser compatibility is no longer an issue, not even for IE.

How might this kind of capability take shape within Dash? I’m lacking the background to answer… so just speculating and guessing it would be quite useful.

#5

The django-plotly-dash library does something similar to what it sounds like you are looking for, essentially by sending a message to a UI component via a websocket and then having that component invoke the callback.

This may sound a bit back-to-front, but it means that the data flow follows that of the rest of Dash, and also can be used directly with other existing Dash components and applications. In particular, the existing Dash infrastructure, based on http requests, is unchanged. You do need to run a websocket-capable server, but you are going to have to do that (or something very similar) to get this sort of server push functionality anyway.

1 Like
Live update by pushing from server (rather than polling or hitting reload)?