How to change Dash interval programmatically while Dash is running?

I start Dash with interval function to make a real-time chart. It reads interval value from CSV file, but once has started, it doesn’t read CSV file anymore so even if I change interval value inside SCV file it doesn’t make any difference.
The main goal is to make it possible to programmatically start, stop and change interval value of the Dash app. A practical use example : my main app is running a few trading strategies and depend on currently most important one - the app will change chart’s data source, stop/start the Dash app with specific interval until the main app tells the Dash to stop or switch to another data source and different interval. I am trying to accomplish this by using CSV file as a medium for communicating the data needed but any solution would be appreciated.

Thanks everyone!

1 Like

Hi @trader007

If yo are using the dcc.Interval component there are a few props that can control when it runs.

You can pause the timer by setting the disabled prop to True. You can control how long the timer runs with the interval and max_interval props. These can be updated in a callback depending on the state of the jobs running.

See these two sections of the docs for more information:

Thanks, AnnMarieW,
Can you make a simple example where the interval is changed programmatically by another .py app while the Dash app is already running. I use PyCharm and can run more than ten .py apps at the time. I succeeded to change the value of the interval but the new value is not actually applied.

SOLVED! I found a solution:
Using code from this link: process - Terminate a python script from another python script - Stack Overflow
How to use: Script (the one with interval function) reads interval value from a CSV file and makes real-time chart and saves pid number (process identification number given by OS) to another CSV file and then another process ( uses, when desired, this pid number to kill (actually restart) the first process, which again reads from CSV file its fresh interval value and other values and starts over.

1 Like