liveBook · Manning

St.plotly_chart

As explained in Build Python Web Apps with Streamlit

st.plotly_chart is a Streamlit API function that renders a Plotly figure in an application.

st.plotly_chart renders a Plotly figure inside a Streamlit app. Create the figure first, then pass it to the function; the result is an interactive visualization rather than a static image. section 6.5.1 section 6.5.2

Use the element to:

  • Display time-series figures with lines, markers, titles, and labeled axes. section 6.5.1
  • Give users built-in zooming, hover tooltips, full-screen viewing, and image download. section 6.5.1
  • Render several metric charts in tabs or place chart components side-by-side with columns. section 6.5.1 section 6.5.2
  • Show charts based on a selected grouping dimension, such as gender, state, category, or product. section 6.5.2

Render a chart across its container

chart = get_time_series_chart(df, metric) st.plotly_chart(chart, use_container_width=True) The first line produces a Plotly figure from prepared data. The second renders it and expands it to the containing box, avoiding oversized charts or unnecessary whitespace. The same pattern renders pie charts. section 6.5.1 section 6.5.2

import plotly.graph_objs as go
import streamlit as st
from data_wrangling import get_metric_time_series
from metric_config import metrics, display_metrics

...
def time_series_chart(df):
  with st.container(border=True):
    chart_tabs = st.tabs(display_metrics)
    for idx, met in enumerate(display_metrics):
      with chart_tabs[idx]:
        chart = get_time_series_chart(df, metrics[met])
        st.plotly_chart(chart, use_container_width=True)

A complete dashboard pattern combines st.plotly_chart with tabs: build a chart for each metric, select the matching tab, and render every figure during the initial load. section 6.5.1

How Build Python Web Apps with Streamlit covers it

How deep it goes
Shows figure construction, container sizing, tabs, grouping, and layout, but defers Plotly and Streamlit internals.
Examples
Uses metric time series, metric-by-dimension pie charts, tabbed dashboards, and side-by-side chart columns.
What it assumes
Assumes a Streamlit app and a prepared Plotly figure or chart-building function.
What you can do after
Operate/configure it to display responsive, interactive Plotly charts in a Streamlit dashboard.
How it connects
Connects Plotly figures with Streamlit tabs, selectbox, columns, and dashboard data aggregation.

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.