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!
Thank you guys for your inspiration and thoughts.
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.
With pleasure @dirk, let us know what you find out