st.spinner() in Streamlit

The spinner method is a context manager in Streamlit used to show a loading indicator while your app is performing a long-running task such as loading data, training models, or reading large files. It displays a temporary spinner with a custom message until the code inside it finishes running.

Syntax

with st.spinner(text="Loading..."):
    # long running process here   

When the code inside this block completes, the spinner disappears automatically.

The function has the following parameter:

Example: Basic usage.

Python

# Importing the Streamlit library
import streamlit as st
import time

st.write("Starting process...")

# Show spinner while waiting
with st.spinner("⏳ Please wait... processing data..."):
    time.sleep(3)  # Simulate a long-running process

st.success("✅ Process completed!")    

Explanation