Hi @KANZ
In this case, you don’t want to use st.experimental_rerun
. You can instead:
- Use
st.empty()
to insert a single-element container that can be used to hold a single element. - Create the success alert in the container from step 1.
- Wait for 1-2 seconds using
time.sleep()
- Clear the container by calling it’s
.empty()
method.
Here’s a working example:
Solution
import time
import streamlit as st
mylist = [1, 2, 3, 4, 5]
if st.button("Click"):
if len(mylist) > 0:
# Insert a single-element container
# that can be used to hold a single element (e.g. st.success)
container = st.empty()
container.success("found") # Create a success alert
time.sleep(2) # Wait 2 seconds
container.empty() # Clear the success alert
for i in range(len(mylist)):
st.write(mylist[i])
Output
You can find similar examples in the st.empty
docs:
Happy Streamlit-ing!
Snehan