Cache gets lost on switching pages with experimental_allow_widgets.
Steps to reproduce
page1.py
import streamlit as st
import time
@st.cache_data(experimental_allow_widgets=True)
def calculate():
time.sleep(1)
if st.sidebar.checkbox("Are you awesome 1?"):
st.write("Hello awesome page 1")
else:
st.write("Hello page 1")
st.write("I am page 1")
calculate()
page2.py
import streamlit as st
import time
@st.cache_data(experimental_allow_widgets=True)
def calculate():
time.sleep(1)
if st.sidebar.checkbox("Are you awesome 2?"):
st.write("Hello awesome page 2")
else:
st.write("Hello page 2")
st.write("I am page 2")
calculate()
pageA.py
import streamlit as st
import time
@st.cache_data()
def calculate(checked):
time.sleep(1)
if checked:
st.write("Hello awesome page A")
else:
st.write("Hello page A")
st.write("I'am page A")
checked = st.sidebar.checkbox("Are you awesome A?")
calculate(checked)
pageB.py
import streamlit as st
import time
@st.cache_data()
def calculate(checked):
time.sleep(1)
if checked:
st.write("Hello awesome Page B")
else:
st.write("Hello Page B")
st.write("I'am Page B")
checked = st.sidebar.checkbox("Are you awesome B?")
calculate(checked)
Steps to reproduce:
Switch between page1 and page2 multiple times. Observe Caching.
Switch between pageA and pageB multiple times. Observe Caching.
Expected behavior:
page1 and page2 use caching.
(page1 and page2 should behave as pageA and PageB)
Actual behavior:
Caching on page1 and page2 does not work. Even without using the Widget.
Caching on pageA and pageB does work as expected.
Debug info
Streamlit version: 1.22.0
Python version: 3.10.8
Using Conda
Additional Info
Caching does work if you stay on that page.
(page1 and page 2 do cache the button state as long as you don’t switch to an other page.)
Thanks for sharing the question and implementations. This seems to be a recurring issue that the Streamlit team is looking into. If you’d like to join in on the discussion (there are a few workarounds that you may find helpful), you can find it in the link below:
Do you mean that the current implementation of “Keyed widget state persistence” is the direct cause of “Experimental_allow_widgets breaking caching for multipage apps”?
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.