Streamlit Placeholders
The next widgets assist in various ways. The first, st.empty
that allows you to have placeholders in your app. This enables you to overwrite certain widget outputs or have multiple widget outputs governed by one placeholder.
with st.empty(): for seconds in range(5): st.write(f"⏳ {seconds} seconds have passed") time.sleep(1) st.write(“✔️ 5 seconds over!”)
placeholder = st.empty() #Replace the placeholder with some text: placeholder.text(“Hello”) time.sleep(2) #Replace the text with a chart: placeholder.line_chart({“data”: [1, 5, 2, 6]}) time.sleep(2) #Replace the chart with several elements: with placeholder.beta_container(): st.write(“This is one element”) time.sleep(2) st.write(“This is another”) time.sleep(2) #Clear all those elements: placeholder.empty()
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy