dcc.Interval as background process

Hello everyone,

I’m actually developping a multi pages app which call a MongoDB database (with pymongo) and will call differents databases for each pages in the futur.

The data in the MongoDB database is updated everyday and depending of my futher use, the next databases will be updated maybe twice a day.

I tried to use dcc.Interval to make the app collecting data from the db every 10 sec (only for testing purpose) and it worked. However when I was switching to an another page, the dcc.Interval callback of the previous page stopped triggering. Whereas I want my graph and table to be updated even if the user go on another page.

I found a relative issue here :

To be able to update the data even in a background process, they speak about websocket. Should I use the dash-extensions websocket provided by @Emil or there is another way ?

Thank you and have a nice day.

Duaran

When you go to a different page is the interval no longer in the layout? It should be possible to do the fetch “in the background” if you put the interval higher up the component tree so that it’s always present and able to trigger callbacks. You might have to fetch the data and put it in an intermediate dcc.Store and update the graph and table from that (so that the callback doesn’t stop executing when the graph and table are not in the layout).

As noted by @tcbegley, the Interval should work as long as you place it high enough in the component tree. It would be the same with the Websocket component :slight_smile:

Hello,

Thank you for your answers. Indeed when I put the dcc.interval in the index.py with a dcc.Store, I was able to get an updated data in the page1.py.

Have a nice day !

1 Like