Besided the dashboarding functionality of my Streamlit application I like to run a scheduled task serveral times a day in the background.
This “background process” retrieves data from an api and stores in a database.
Does anyone has an idea if and how such a functionality can be implemented, respectively?
This is not something we support natively today. You can have a look at this component st-auto-refresh but while it will rerun the app on a regular interval within a viewer’s session, I believe as such it won’t ensure a task to run at a specific interval, regardless viewers or sessions. Give it a try!
On another note, you could throw an eye at databutton which enables you to build Streamlit apps and also offers services on top, like a decorator to schedule tasks@db.jobs.repeat_every(seconds=60 * 10, name="Check hackernews"). Looks pretty tailored to your need, but I never tried and don’t know how flexible that is!
I do this myself but not with streamlit.
The way I do this works for locally hosted apps. Not sure about cloud apps.
I have a Python script that pulls data from an API and updates a local database (but could just as easily be a csv file).
I then wrote a windows batch file to execute this script.
Then I use windows task scheduler to run this script periodically.
Then separately I have a streamlit app that calls the database and displays the front end content.
Yes @LukeF I’m tempted by the idea of having all data stuffs in the same place and schedule jobs from a Streamlit app, but indeed some would argue that separation of concerns is more reasonable. It looks like a very convenient feature in a cloud setup, though!
Implementing a seperated cron job (or task on windows) would of course be an option - and I guess that this will be the way I may implement this in the end. But a solution within the app itself could also be a nice solution.
The databutton thing seems quite interessting anyway, I will take a closer look at it.
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.