What are Data Apps?
Jupyter notebooks are great for exploration, but they aren't the best way to share your findings with non-technical stakeholders. A data app is a simple web application that presents your data analysis in an interactive format, often with widgets like sliders, dropdowns, and buttons that allow users to control the analysis.
Streamlit is an open-source framework that makes building these apps incredibly simple. You write a standard Python script, and Streamlit renders it as a web app. There's no HTML, CSS, or JavaScript required.
How to Run a Streamlit App
- Installation: pip install streamlit
- Create a Script: Write your app code in a file, for example, my_app.py.
- Run from Terminal: Open your terminal, navigate to the folder with your script, and run: streamlit run my_app.py. A new tab will open in your browser with your live app.
Core Concept: Magical Reactivity
The magic of Streamlit is its reactivity. Whenever you interact with a widget (e.g., move a slider), Streamlit re-runs your entire script from top to bottom. This simple execution model makes it very easy to reason about your app's logic.
A Full Example: An Interactive Penguin Explorer App
Let's build a simple app that loads the Palmer Penguins dataset, allows the user to select one or more species using a multiselect widget, and displays an interactive scatter plot for the selected species.
Save this code as a Python file (e.g., penguin_app.py):
Python
# penguin_app.py
import streamlit as st
import pandas as pd
import plotly.express as px
# --- PAGE CONFIGURATION ---
# This must be the first Streamlit command in your script.
st.set_page_config(
    page_title="Palmer Penguin Explorer",
    page_icon="🐧",
    layout="centered"
)
# --- DATA LOADING AND CACHING ---
# Use st.cache_data to prevent reloading the data on every interaction.
@st.cache_data
def load_data():
    # Load the penguin dataset from its URL
    url = "https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/inst/extdata/penguins.csv"
    df = pd.read_csv(url)
    return df
penguin_df = load_data()
# --- APP TITLE AND DESCRIPTION ---
st.title("🐧 Palmer Penguin Explorer")
st.markdown("""
This app allows you to explore the relationship between the culmen (bill) dimensions
of three different penguin species from the Palmer Archipelago.
""")
# --- SIDEBAR FOR USER INPUTS ---
st.sidebar.header("Filter Options")
# Get the list of unique species for the multiselect widget
species_list = ["All"] + sorted(penguin_df["species"].unique().tolist())
# Create a multiselect widget in the sidebar
selected_species = st.sidebar.multiselect(
    "Select Penguin Species:",
    options=species_list,
    default="All"
)
# --- FILTER THE DATAFRAME BASED ON SELECTION ---
if "All" in selected_species:
    filtered_df = penguin_df
else:
    filtered_df = penguin_df[penguin_df["species"].isin(selected_species)]
# --- MAIN PANEL DISPLAY ---
st.header("Penguin Data")
# Display the filtered dataframe
st.dataframe(filtered_df.head())
st.write(f"Displaying data for **{filtered_df.shape[0]}** penguins.")
st.header("Culmen Length vs. Depth")
st.write("An interactive scatter plot showing culmen dimensions for the selected species.")
# Create an interactive scatter plot with Plotly
if not filtered_df.empty:
    fig = px.scatter(
        filtered_df,
        x="culmen_length_mm",
        y="culmen_depth_mm",
        color="species",
        hover_name="species",
        title="Culmen Length vs. Culmen Depth"
    )
    # Display the Plotly chart in the Streamlit app
    st.plotly_chart(fig)
else:
    st.warning("No data to display for the selected species.")
When you run streamlit run penguin_app.py, you will get a web app with a sidebar. Changing the species in the multiselect widget will instantly re-run the script, filter the DataFrame, and update the data table and the plot on the main page.