liveBook · Manning

Radio button

As explained in Build Python Web Apps with Streamlit

st.radio is a Streamlit selection element that lets a user choose one value from a set of options.

A radio button lets a user choose exactly one value from a list. In Streamlit, st.radio displays the choices and stores the selected option in a Python variable. section 3.6.1

Choose a quantity

quantity = st.radio("Select a quantity", ["Mass", "Length", "Time"]) This displays three choices. After selection, quantity contains the chosen string, such as "Mass". The options can begin as a hardcoded list and later come from a backend. section 3.6.1

Use radio buttons when the interface needs one choice from a visible set:

  • Place the control in the sidebar with st.sidebar.radio(...) when it belongs in a left-side panel. section 3.6.1
  • Use the selected value to drive later controls; the unit converter updates its From and To menus after a quantity is chosen. section 3.5.3
  • Customize the presentation by arranging options horizontally, adding captions, or disabling them when appropriate. section 3.6.1
quantity = st.radio("Select a quantity", ["Mass", "Length", "Time"])

Inspect the minimal st.radio call that creates the quantity selector and returns the selected option. section 3.6.1

How Build Python Web Apps with Streamlit covers it

How deep it goes
Defines selection behavior, demonstrates basic placement, and lists customization options without examining widget internals.
Examples
Uses Mass, Length, and Time choices in a unit-converter quantity selector, including a sidebar variant.
What it assumes
Assumes basic Python and Streamlit setup while introducing radio-button behavior from a visible working example.
What you can do after
Apply it via Streamlit to capture one selected option and use that value in subsequent interface logic.
How it connects
Connects radio buttons with Streamlit, sidebar layouts, selectboxes, backend configuration, and dependent interface updates.

Also explained in

Compare how 4 books explain radio button →

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.