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

I am using a Python shell to interactively run simulations and write data to a file. I have a dash app which renders a bunch of interactive plots from this data. I’d like the dash app to show new data after each run.

Dash’s Live Updating Components page gives two options:

  1. Create a dcc.Interval on the client and have it poll for changed data
  2. Set app.layout = serve_layout to force a page reload to serve a new dynamic layout

The first seems a bit loose (but I guess the check for new data could be kept light) and the second requires the user to hit reload.

So, is there a way for my python process to tell the dash server to trigger a reload? Or some other approach I’ve missed?

1 Like

I posted this in response to a similar question:

hot-reloading does this for development environments. Since you are saving files, I’m not sure if the hot reloader will pick up on the changes to the file unless you place them in your assets folder 📣 Announcing Hot reload.

Thanks @delsim, this is probably overkill for my current problem. However I’m interested in the architecture for a longer term problem. Is there a design pattern that captures this technique, or is the approach in wider use by web developers do you know?

Thanks @chriddyp, this is a great solution for my current problem and seems to work well.

For anyone reading this, I created an assets folder next to my and literally just touch an empty file in here to trigger a reload:

from pathlib import Path

Then requires app.layout = serve_layout to force a page reload to serve a new dynamic layout.