Auto update/reload dashboard connected to mongodb

Hi all.
I am developing a dashboard and data is coming from MongoDB. Everything works properly but I cannot have automatic reload (internal) and I need to restart the dashboard to fetch the latest data from the database.

Also, I think callback(input, output ) cannot help me because after fetching data I will not use it directly. I use panda to make a data frame, and then I read the data frame and use some fields in the dashboard. Is there any solution to just fetch new data and then process it?

database = client["db"]
collection = database["results"]
data = pd.DataFrame(list(collection.find()))

It’s a part of my code when I want to fetch data from the database and then I use some fields in the data frame in my dashboard.

The easiest way to fetch new data regularly in the app is to store it in a dcc.Store component. You can combine it with dcc.Interval as input, so the callback will be triggered regularly. Just note that 1- dcc.Store data needs to be a dictionary, not a pandas DataFrame and 2- the data will be sent to the client (and back to the server if you use it as Input to other callbacks).

A related discussion can be found here, notably the part about server-side caching that might be relevant for you if you are fetching a lot of data.

1 Like

thanks alot.