Is there a way to rerun based on time?

I’m working on a streamlit dashboard which loads live data, predicts and displays a plotly chart.

I’ve got it all working, but I’m stuck on how to make it rerun every 5 minutes. Is there an elegant way to do this in streamlit?

Currently I was thinking of just putting the whole streamlit output in a while loop like:

@cache
get_live_data(time)
    # all the

while True:
    time.sleep(5_mins)
    data = get_live_data  # this gets new data but how to rerun the script now?

# or do i need to put all the stuff inside the while loop like so
while True
    all_the_code()
   time.sleep(5_mins)

but, since the script never ends, what does that mean for streamlit? Is this a bad thing? does streamlit expect things to end at some point?

I’d love to have a streamlit call like st.rerun(after=5 minutes) which I can stick anywhere and it just autoruns.

Hey @khalido

@thiago made 2 st.rerun gists here and here that you can reuse :slight_smile: you can then start a timer at the top of your file and call rerun when 5 minutes went by, or edit the rerun snippet to include a after argument and start the timer in the gist.

Hope that works well for you,
Fanilo

2 Likes