Spaces:
Sleeping
A newer version of the Streamlit SDK is available:
1.48.1
title: Execution flow
slug: /develop/api-reference/execution-flow
Execution flow
Change execution
By default, Streamlit apps execute the script entirely, but we allow some functionality to handle control flow in your applications.

Modal dialogs
Insert a modal dialog that can rerun independently from the rest of the script.
@st.experimental_dialog()
def email_form():
name = st.text_input("Name")
email = st.text_input("Email")
Partial reruns
Define a fragment to rerun independently from the rest of the script.
@st.experimental_fragment(run_every="10s")
def fragment():
df = get_data()
st.line_chart(df)
Rerun script
Rerun the script immediately.
st.rerun()
Stop execution
Stops execution immediately.
st.stop()
Group multiple widgets
By default, Streamlit reruns your script everytime a user interacts with your app.
However, sometimes it's a better user experience to wait until a group of related
widgets is filled before actually rerunning the script. That's what st.form
is for!
Forms
Create a form that batches elements together with a “Submit" button.
with st.form(key='my_form'):
name = st.text_input("Name")
email = st.text_input("Email")
st.form_submit_button("Sign up")
Form submit button
Display a form submit button.
with st.form(key='my_form'):
name = st.text_input("Name")
email = st.text_input("Email")
st.form_submit_button("Sign up")

Autorefresh
Force a refresh without tying up a script. Created by @kmcgrady.
from streamlit_autorefresh import st_autorefresh
st_autorefresh(interval=2000, limit=100,
key="fizzbuzzcounter")

Pydantic
Auto-generate Streamlit UI from Pydantic Models and Dataclasses. Created by @lukasmasuch.
import streamlit_pydantic as sp
sp.pydantic_form(key="my_form",
model=ExampleModel)

Streamlit Pages
An experimental version of Streamlit Multi-Page Apps. Created by @blackary.
from st_pages import Page, show_pages, add_page_title
show_pages([ Page("streamlit_app.py", "Home", "🏠"),
Page("other_pages/page2.py", "Page 2", ":books:"), ])