Best practices for live updates
See original GitHub issueHi,
I’m working on a dashboard that queries the database every 1 minute and updates various charts with the new data. I noticed some strange behavior with the live updates. Most of the time everything works fine, but occasionally some of the charts gets updated with old data (like, data that’s 5 or 10 minutes ago), which doesn’t make sense to me. Checked the database and the data there are always up to date.
Initially, I have set up callback functions for each of the charts with events=[Event('interval-component', 'interval')] as the trigger. I have a separate callback function which does the database query and updates data in a few global variables, which are used for charts plotting.
I suspect it might be due to some race condition problem - the charts are getting updated with the event trigger, but the data update has not finished yet. So I changed the condition for the callback. Now I have one callback function which gets triggered every one minute and pulls latest data (into global variables) from the database and updates a div on my page with a timestamp. Then, all the other charts watch the timstamp div and update themselves (using the global variables) if there is any changes. I thought this may ensure that my database query finishes first before the charts get updated. However, it seems it still has not solved the problem.
So I would like to know what is the best practice for handling such live updates. e.g.
- Is it a good idea to store the data in global variables? I don’t want to have repeated database queries for each chart so I just want to do it in one go.
- If
events=[Event('interval-component', 'interval')]are used for updating multiple components, in what sequence does Dash execute the callback functions?
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)

Top Related StackOverflow Question
@RLstat - check out https://plot.ly/dash/live-updates
Hi, I’m now trying to use Dash with multiple Interval elements (with different update time), using the solution with gunicorn, but seems that it’s not working. Is there any solutions for multiple Interval?