Delete placeholder

Is there any way to delete a placeholder or a progress bar once complete and no longer any use?

1 Like

Hello @dazmundo, welcome to the Streamlit forums!

Every non-interactive Streamlit element can be replaced by another element by calling another element on the returned object. For example:

import streamlit as st
import pandas as pd
import time

df = pd.DataFrame({'col1': [1,5,2]})

# Show a dataframe
element = st.dataframe(df)

# Wait 5 seconds
time.sleep(5)

# Replace the dataframe with a chart
element.line_chart(df)

So you can do the same thing with an st.progress element, but since you want it to disappear you’d replace it with an st.empty:

import streamlit as st
import time

my_bar = st.progress(0)
for i in range(100):
    my_bar.progress(i + 1)
    time.sleep(0.01)

my_bar.empty()  # Remove the progress bar
st.write("Done!")

(Note that this doesn’t currently work with buttons and other interactive widgets.)

1 Like

Hi @dazmundo

Regarding your comment “doesn’t currently work with buttons and other interactive widgets” are you in fact considering changing the api so that you always get the an element back?

I think that is worth at least considering because that would simplify the api and make it work the same for non-interactive and interactive widgets. And to me Streamlit is all about simplifying the experience.

I have a feeling that I would have been the right api from the beginning.

Marc

Thanks for that.

1 Like