Auto refreshing a multipage app

Summary

Hi,
i created a multipage app that displays a dataframe which gets updated in regular intervals using streamlit autorefresh component and by using st.cache to not get updated whenever there is a user_interaction , but when page is not opened the st_autorefresh is not getting triggered , so when page1 is opened it is getting refreshed but page 2 is not getting refreshed in the interval and when i open page2 since the cache got cleared it is getting refreshed due to user_interaction.

Steps to reproduce

i tried to reproduce this issue by creating a similar problem

Code snippet:
“main.py” - main_page

import streamlit as st
import time
import pandas as pd
from datetime import datetime
from streamlit_autorefresh import st_autorefresh


time_threshold=2



if "count1" not in st.session_state:
    st.session_state.count1=0
if "time" not in st.session_state:
    st.session_state.time = (time_threshold*60)





@st.cache_data(ttl=st.session_state.time)
def hi(y):
    now = datetime.now()
    time_formatted = now.strftime("%d/%m/%y %H:%M:%S")
    st.text(time_formatted)



st.session_state.count1+=1

hi(2)
st.text(st.session_state.count1)

st_autorefresh(interval=st.session_state.time*1000, key="main_Refresh",debounce=False)

“page2”:

import streamlit as st
import pandas as pd
import time
from datetime import datetime
from streamlit_autorefresh import st_autorefresh


time_threshold1=2


if "count" not in st.session_state:
    st.session_state.count=0
if "time1" not in st.session_state:
    st.session_state.time1 = (time_threshold1*60)





@st.cache_data(ttl=st.session_state.time1)
def hello(y):
    time2 = datetime.now()
    time_formatted = time2.strftime("%d/%m/%y %H:%M:%S")
    st.text(time_formatted)

st.session_state.count+=1
st.text(st.session_state.count)

hello(2)

st_autorefresh(interval=st.session_state.time1*1000, key="main_Refresh",debounce=False)

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

the page gets refreshed even when the page is not open at the given intervals

Actual behavior:
the page is getting refreshed only when the page is opened

Debug info

  • Streamlit version: 1.24.1
  • Python version: 3.11.2
  • Using PyEnv
  • OS version:
  • Browser version:

Appreciate any replies
Thank you

1 Like

Hi @saitharun_gunasekar,

Thanks for sharing this question. Just to clarify – you want a specific page in your multipage app to autorefresh using the streamlit_autorefresh package even if the user is not viewing that page?

yes @Caroline

Any update on this @Caroline

I wrote a response to this in the GitHub issue for autorefresh Auto refreshing a multipage app · Issue #9 · kmcgrady/streamlit-autorefresh · GitHub

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.