My dashboard downloads data files which are refreshed every day. This takes about a minute. Is there a way within streamlit to easily call specific functions when the app launches, rather than having the user wait for the initial download?
Similarly, are there any recommended methods to ensure cached data provider functions are called/refreshed on a regular interval.
Would apscheduler or similar work within streamlit?
If you are deploying on Streamlit Cloud you are more limited than if you have control over the infrastructure serving your app.
If you have control over the infrastructure, you could use whatever scheduling was available within that system.
As for Streamlit Cloud, the only recommendation I have is to schedule some computer somewhere to connect to your app at 1 AM, so that it can do any of your more expensive computations that you want to cache. (For example, if you have a get_data(date) function that is cached, then by passing in the date, it will use the cache until the date changes…modulo some cleanup depending on how much data is being cached and how long your app runs between reboots.)
I made an example of a script that connects to a Streamlit app. This could be packaged up in a bat file and scheduled for instance.
Hey Debbie! I’m looking to host this as a service within our docker swarm. Using selenium to trigger streamlits internal refresh is smart.
Do you know of any way to do it without external scripts or similar?
I’m most worried about service bloat - having one service which uses streamlit run to serve the dashboard and something internal to refresh it would be more elegant than one service to serve, and another to trip the refresh.
If there isn’t something, I wonder if the team would be open for a FR or PR to implement it
I don’t have anything slicker than the Selenium script. That can live most anywhere, even the same service offering up the Streamlit app if it’s a service you control.
I know I have heard other mentions on the forum about people wanting to schedule their app to do things autonomously in various situations. If it’s just updating files outside of Streamlit, that can be scripted anywhere. So the biggest argument for a Streamlit feature specifically (that I know of) is wanting to get the cache updated on some regular basis so the first user of the day isn’t hit with a wait time.
I did a quick search of Issues on GitHub, but didn’t find it posted there. I have definitely read posts touching on it in the forum, though. Streamlit staff are very happy to get feature requests recorded in GitHub and I think options within the config file to specify some autonomous execution would be nice, specifically targeting optimal cache performance.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.