Data Visualization

Plotly + Dash

01 · What is Dash? File · Plotly + Dash · 1 of 9

What is Dash?

Plotly creates interactive charts.

Dash connects those charts together and turns them into an interactive website / dashboard.

Plotly → Creates charts
Dash → Combines charts + filters + KPIs into a full web app

Think of Plotly as individual furniture pieces and Dash as the complete furnished room.
02 · Plotly vs Dash File · Plotly + Dash · 2 of 9

Building a House Analogy

  • Python → Land
  • Pandas → Workers handling data
  • Plotly → Interior designer creating graphs
  • Dash → Architect combining everything into one dashboard
You first learn Plotly to make good charts. Then you learn Dash to put those charts into a live, interactive website that users can filter and explore.
03 · Install & Import File · Plotly + Dash · 3 of 9

Install and Import

Python
# Install the libraries (quiet mode)
# !pip install plotly dash -q

import pandas as pd                 # work with tabular data
import numpy as np                   # numerical operations
import plotly.express as px         # quick interactive charts
import plotly.graph_objects as go   # more control over charts

from dash import Dash, dcc, html, Input, Output, callback
Dash → Creates the application
dcc → Dash Core Components (Graph, Dropdown, Slider…)
html → Create webpage elements (H1, Div, P…)
Input → Tells Dash: “Watch this component for changes”
Output → Tells Dash: “Update this component after something changes”
04 · Core Components File · Plotly + Dash · 4 of 9

Important Dash Components

ComponentPurpose
html.H1()Main heading
html.P()Paragraph text
html.Div()Container (like a box)
dcc.Graph()Displays a Plotly figure
dcc.Dropdown()Dropdown filter
dcc.RangeSlider()Slider for numbers
Almost every interactive element you see in a Dash dashboard is either an html element or a dcc component.
05 · Basic Layout File · Plotly + Dash · 5 of 9

Basic Dashboard Layout

Python
app = Dash()

app.layout = html.Div([
    html.H1("Bank Marketing Dashboard"),
    html.P("Select a Job"),
    dcc.Dropdown(
        id="job-dropdown",
        options=["Manager", "Technician", "Admin"],
        value="Manager"
    ),
    dcc.Graph(id="balance-chart")
])
id is extremely important.
The id is how the callback knows which component to watch and which component to update.
06 · Callback Explained File · Plotly + Dash · 6 of 9

How Callbacks Work (Line by Line)

Python
@callback(
    Output("balance-chart", "figure"),   # What should be updated?
    Input("job-dropdown", "value")      # What should we watch?
)
def update_chart(selected_job):
    # 1. Filter the data based on the selected job
    filtered_df = df[df["Job"] == selected_job]

    # 2. Create a new chart with the filtered data
    fig = px.bar(
        filtered_df,
        x="Job",
        y="Balance",
        title=f"Balance Analysis - {selected_job}"
    )

    # 3. Return the figure so Dash can display it
    return fig
Very Important:
The id used in Input() and Output() must exactly match the id you gave in the layout.
If you write "job-dropdown" in one place and "job_dropdown" in another, the callback will not work.
07 · Complete Working App File · Plotly + Dash · 7 of 9

Complete Working Example (Corrected)

Python
from dash import Dash, html, dcc, Input, Output, callback
import pandas as pd
import plotly.express as px

# Sample data
df = pd.DataFrame({
    "Job": ["Manager", "Technician", "Admin",
           "Manager", "Technician", "Admin"],
    "Age": [45, 32, 29, 51, 40, 35],
    "Balance": [50000, 25000, 18000,
               72000, 38000, 30000]
})

# Create the app
app = Dash()

# Layout
app.layout = html.Div([
    html.H1("Bank Customer Dashboard"),
    html.P("Select Job"),
    dcc.Dropdown(
        id="job-dropdown",          # ← This ID must match Input
        options=df["Job"].unique(),
        value="Manager"
    ),
    dcc.Graph(id="balance-chart") # ← This ID must match Output
])

# Callback
@callback(
    Output("balance-chart", "figure"),
    Input("job-dropdown", "value")
)
def update_chart(selected_job):
    filtered_df = df[df["Job"] == selected_job]
    fig = px.bar(
        filtered_df,
        x="Job",
        y="Balance",
        title=f"Balance Analysis - {selected_job}"
    )
    return fig

# Run the app
if __name__ == "__main__":
    app.run(debug=True)
What the dashboard looks like
Bank Customer Dashboard Select Job Manager ▼ Balance by Job (updates when dropdown changes)
When you change the dropdown, the bar chart updates automatically
08 · Common Errors Fixed File · Plotly + Dash · 8 of 9

Errors Found in the Original Notebook & Fixes

1. ID Mismatch (Most Common Error)

Wrong
Layout: id="job_dropdown"
Callback: Input("job-dropdown", "value")
Fix: Both places must use exactly the same ID (either both with underscore or both with hyphen).

2. Column Name Case Sensitivity

Using df["job"] when the real column is "Job" (or vice-versa).
Always check exact column names with df.columns before writing filters.

3. Incomplete Callback

Some callbacks were written but never connected to a proper layout. Always make sure every Input and Output has a matching component in the layout.

09 · Summary File · Plotly + Dash · 9 of 9

Summary

  • Plotly → Creates interactive charts
  • Dash → Turns charts into a full interactive dashboard
  • Use html for page structure
  • Use dcc for interactive components
  • Use @callback to make the dashboard respond to user actions
  • Always keep the id names consistent between layout and callback
Once you understand the pattern (Layout → Callback → Filter → Update Chart), you can build almost any interactive dashboard.
Home Plotly + Dash

Plotly + Dash

Turn interactive charts into complete web dashboards with filters and live updates.

Select any topic from the left sidebar to begin.


Start Learning →