liveBook · Manning

St.dialog

As explained in Build Python Web Apps with Streamlit

st.dialog is a Streamlit decorator that presents a function's interface in a modal dialog and supports rerunning that dialog independently.

Need a detailed view without crowding the main dashboard? `st.dialog` turns a Python function into a modal dialog: its interface appears over the app, temporarily blocking interaction with the page beneath it. It is a decorator, not a container like `st.tabs` or `st.container`. section 7.5.1

Listing 7.1 A drilldown dialog
import streamlit as st

@st.dialog("Drilldown", width="large")
def drilldown(main_df, compare_df):
  main_tab, compare_tab = st.tabs(["Main", "Compare"])
  with main_tab:
    st.dataframe(main_df, use_container_width=True)
  with compare_tab:
    st.dataframe(compare_df, use_container_width=True)

The drilldown example decorates a function with `@st.dialog("Drilldown", width="large")`. Calling that function with two dataframes opens a dialog with Main and Compare tabs. The `width` option can be `small` (500 pixels) or `large` (750 pixels). section 7.5.1

A button can trigger the decorated function. Unlike an ordinary app-wide rerun, interacting with a widget inside the dialog reruns only that function. This lets a drilldown dimension selector update the dialog without clearing the triggering button’s clicked state. The behavior comes from `st.fragment`. section 7.5.3

Save from a dialog

An Add Haiku button opens a dialog containing a text area and Save button. Saving calls a service that writes to a database and reports success or failure. On success, `st.rerun()` reruns the whole app, closing the dialog because its triggering button is no longer clicked. This deliberate full rerun differs from a widget interaction that reruns only the dialog. section 8.5.2

How Build Python Web Apps with Streamlit covers it

How deep it goes
Shows decorator setup, button-triggered opening, width options, and dialog-only reruns; attributes rerun behavior to st.fragment without detailing its internals.
Examples
Uses a two-tab dataframe drilldown and a haiku editor with text entry, database saving, and success or failure messages.
What it assumes
Assumes Python functions and basic Streamlit widgets while explaining how the decorator differs from container widgets.
What you can do after
Build it from scratch: open an interactive Streamlit dialog from a button and choose when to rerun the whole app.
How it connects
Connects modal dialogs to Streamlit buttons, st.fragment, st.rerun, tabs, and pandas dataframes.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.