Live update from a database/file

Hi everyone! So I have a database with some data that I would like to use for creating a live dashboard. Specifically, whenever a row is added or deleted from my database, I want to trigger a callback on my app. Similarly, I have a json file that I would like it to trigger a callback whenever modified. How can this be accomplished?

I am aware of the Intervals component in dash core, but my intended behavior seems to be different: with the Interval component I set a time and a callback will be triggered after that time, independently of the number of modifications made to the database/json file. Ideally, I would like a callback to be triggered after each modification. I guess I could always make the listening time very small but I am curious on whether there is a native/dashy way to do this. Any thoughts?

Hi, you might take a look at dash-extensions.

1 Like

I agree that you need a solution based on sockets i.e. websockets. But dash-extensions websocket component in my case is partially useful for example - I change data serverside and clientside the value is not updated…unless I have to reload the page or restart the server…

Is this really the case? I would expect the data to change clientside too. Otherwise what would be the use case of websockets?

May be I do something wrong. I read in the documentation that app.run() method disables reloader because it is in development mode. There is an option to set use_reloader true or false in app.run() but did not work. So, reloader may be works only in deployment mode with hypercorn. All the above refer to quart which is the server used in dash-extensions. I do not know the extent of quart coverage by dash-extensions websocket component.

In my case Websockets component works well with a local Quart server in development mode. When accessing from a deployed Dash app I needed to increase the asyncio.sleep time a bit after the websocket.send_json statement on the Quart server. Otherwise no data were streamed.

Hello my friends.
The problem is that updating is only available in production with hypercorn server running. In development mode no updating (reloader)…In my case I run the apps in docker. I shall try to setup a hypercorn server and check it.

I have a dynamic dataset, and I’m eager to create a live dashboard that updates in real-time whenever there’s a change in the underlying data. I want a callback to be triggered every time a new data point is added or an existing one is removed. While I’m familiar with using the Interval component in Dash for periodic updates, it seems that my use case is a bit different. Instead of relying on a fixed time interval, I want the callback to fire instantly upon any modification to the dataset.

Yep, websocket component works in this way. Whenever you’ll receive new data, property ‘message’ is firing and can be used in a callback. See Dash