Anyone hosting Dash in GCP? If you set the instances to ONE in Cloud Run there is no cold start, but then if you python code need to grab new data then that doesn’t run. I had read one post that the if the code is in a function it should update, but I’m only getting it to updated periodically and with the “cold start”. Any best practice suggestions here?
Thanks,
Eric
Are you reading the data in the app, and then defining the layout and calling app.run()?
If you do that the data will be read only once when when the app starts, not each time a user opens a browser session onto it. (And the app may run for a long time, and many browser sessions may connect to it).
If you want it to load up-to-date data each time a browser session connects, one approach is to put the data load into a callback that’s triggered when a browser session starts.
I regret I don’t have a link to any example code that shows this.
(And if you want to update the displayed data during a browser session, you could use dcc.Interval() to periodically trigger a callback that updates the data)
@davidharris thank you for that info!
Yes its basically DB connections, SQL/Dataframes populated followed by the “app.run” that displays the data and changes based on what is in my callback functions. I’m going to try your suggestions, seems like the dcc.interval() could be run in my call back function each time the user selects new data in the dropdown on the web app.
Thanks,
Eric
dcc.Interval() probably isn’t something to put inside a callback. It usually sits in the layout, and is a way of triggering callbacks every few seconds, so it gives a way of updating the display without any user action being needed.
Alternatively, if you only want to update when the user clicks on something, you probably don’t need dcc.Interval(), you can just have the user action trigger the callbacks