Summary
When a function (decorated with @cache_data) is running and a spinner is automatically shown, some widgets are displayed twice. The duplicates are disabled and are only visible until the processing phase is finished:
Debugging Info
- I am running the app locally
- I managed to reproduce the error on a simple streamlit script without any external library requirements
- Python 3.9.5
- Streamlit, version 1.42.0
Reproduce Sample
- Run the following streamlit code:
import streamlit as st
import time
# Simulate long-running cached functions
@st.cache_data
def long1(i):
print(f'long1({i})')
return i
@st.cache_data
def long2(i):
print(f'long2({i})')
time.sleep(5) # Simulate delay
return i * 2
if __name__ == '__main__':
if 'step' not in st.session_state:
st.session_state['step'] = 0
if st.button('button1'):
st.session_state['step'] = 1
if st.session_state['step'] > 0:
st.write(sum([long1(x) for x in range(5)]))
with st.expander('first'):
st.write('text 1')
with st.expander('second'):
st.write('text 2')
if st.button('button2'):
st.write(sum([long2(x) for x in range(2)]))
- Open the webpage and click on
button1→ You should see ast.writeand 2 simplest.exapnderwidgets - Click on
button2→ Whilelong2()is running, thest.writeand thest.expanders are duplicated under the spinner in disabled mode. - When the processing finishes, the duplicate widgets disappear and the resuling
st.writeis shown.
