How can I use time.sleep() only for "success", "warning" and "info"

I just want the st.success mark to go away after 1-2 seconds.

if st.button("Click"):
       if len(list) > 0:
              for i in range(len(list)):

When I use “st.experimental rerun()”, my outputs (list[i] values) are also disappear

Hi @KANZ :wave:

In this case, you don’t want to use st.experimental_rerun. You can instead:

  1. Use st.empty() to insert a single-element container that can be used to hold a single element.
  2. Create the success alert in the container from step 1.
  3. Wait for 1-2 seconds using time.sleep()
  4. Clear the container by calling it’s .empty() method.

Here’s a working example:


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)):



You can find similar examples in the st.empty docs:

Happy Streamlit-ing!
Snehan :balloon:

1 Like

Thank you for this information :raised_hands::green_heart: