Course contentsShow
← Data Science
Lesson 1332 of 2,14533. Advanced Visualization TechniquesFree lesson

Streamlit Widgets: Inputs and Controls

Use sliders, text inputs, selectboxes, and buttons to create interactive controls that update visualizations.

Streamlit Widgets: Inputs and Controls

What You'll Learn

You'll learn how to add interactive controls like sliders, text inputs, selectboxes, and buttons to your Streamlit dashboards to let users dynamically update visualizations.

The Core Idea

Think of widgets as the "control panel" of your dashboard. Just as a car's steering wheel and pedals let you control the vehicle's behavior, Streamlit widgets let users control what data they see and how it's visualized. Each widget captures user input, which you can immediately use to filter data, adjust parameters, or redraw charts.

When a user interacts with any widget, Streamlit automatically reruns your script from top to bottom with the new values—making your dashboard reactive without complex callbacks.

Common Widget Types

Sliders let users select numeric values within a range—perfect for filtering years, adjusting thresholds, or setting parameters:

age_filter = st.slider("Select age range", 0, 100, (25, 65))

Text inputs capture free-form text for searches or custom labels:

search_term = st.text_input("Enter search term")

Selectboxes provide dropdown menus for choosing from predefined options:

chart_type = st.selectbox("Choose chart type", ["Bar", "Line", "Scatter"])

Buttons trigger specific actions when clicked:

if st.button("Generate Report"):
    # Code runs only when button is clicked
    st.write("Generating...")

Connecting Widgets to Visualizations

The real power comes from using widget values to update your plots. The returned values from widgets can directly filter DataFrames, adjust visualization parameters, or switch between different chart types—all updating in real-time as users interact.

Key Takeaway: Streamlit widgets transform static visualizations into interactive dashboards by capturing user input and automatically re-rendering your app with updated values, creating a responsive analytical experience without complex programming.