liveBook · Manning

Go.Pie

As explained in Build Python Web Apps with Streamlit

go.Pie is the Plotly Graph Objects trace class for representing pie-chart sectors from labels and values.

go.Pie is a Plotly Graph Objects trace for turning grouped labels and values into pie-chart sectors. Labels appear in the color legend, while values determine each sector's size. section 6.5.2

Create a donut chart

Group data by a dimension, then add one go.Pie trace to a Figure. Setting hole=0.4 changes the pie into a donut chart.

Listing 6.11 Displaying a pie chart
import plotly.graph_objects as go
from data_wrangling import get_metric_grouped_by_dimension

def get_pie_chart(df, metric, dimension):
  data = get_metric_grouped_by_dimension(df, metric, dimension)
  fig = go.Figure()
  fig.add_trace(
    go.Pie(labels=data[dimension], values=data['Value'], hole=0.4)
  )
  return fig

Use the compact implementation to inspect the relationship between grouped data, labels, values, and the donut hole. section 6.5.2

How Build Python Web Apps with Streamlit covers it

How deep it goes
Explains labels, values, and hole, then demonstrates a small implementation; it stops short of advanced styling.
Examples
Uses grouped product sales, selectable dimensions, metric tabs, and a completed dashboard placing pie and time-series charts together.
What it assumes
Assumes Python data preparation and dashboard context while demonstrating the chart trace and its inputs directly.
What you can do after
Build it with Plotly Graph Objects, aggregate values by dimension, and display the result inside a Streamlit dashboard.
How it connects
Connects pie charts with Plotly Graph Objects, pandas groupby, Streamlit selectbox, tabs, columns, and chart rendering.

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.