I just stumbeld upon the cache parameter in the st.spinner function.
I looked into the documentation and found no explaination about what it does. By looking at older version of Streamlit I concluded that it was added with the release of verision 1.28
I just confirmed: it’s currently something used internally, but you can set it manually if you want. If you set cache=True the spinner widget will not be inline and instead float above page content, which prevents elements that follow the spinner from jumping down and back up if you use st.spinner on a script rerun.
import streamlit as st
import time
a,b = st.columns(2)
with a:
st.markdown("Before")
with st.spinner("Running"):
time.sleep(2)
st.markdown("After")
st.markdown("After")
st.markdown("After")
with b:
st.markdown("Before")
with st.spinner("Running", cache=True):
time.sleep(2)
st.markdown("After")
st.markdown("After")
st.markdown("After")