st.empty() in Streamlit

The st.empty() in Streamlit is a single-element placeholder — an empty container in your app where you can later insert or update content without reloading the entire page.

Think of it as reserving a spot in your app that can be dynamically filled with text, charts, progress bars, or other elements.

Basic Syntax

placeholder = st.empty()    

Now you can update it later:

placeholder.text("Loading...")
time.sleep(2)
placeholder.text("Done!")    

Example: Live-updating Text

Python

import streamlit as st
import time

status = st.empty()

for i in range(5):
    status.write(f"Step {i+1} in progress...")
    time.sleep(1)

status.write("✅ All steps completed!")    

Example: Progress Bar with st.empty()

Python

import streamlit as st
import time

progress_text = st.empty()

for i in range(101):
    progress_text.text(f"Progress: {i}%")
    time.sleep(0.05)

progress_text.text("Done!")    

Key Uses