<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Esther on Medium]]></title>
        <description><![CDATA[Stories by Esther on Medium]]></description>
        <link>https://medium.com/@esthersm?source=rss-db08db068da8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SmYhAFhdcYOXbmemlUHUcQ.png</url>
            <title>Stories by Esther on Medium</title>
            <link>https://medium.com/@esthersm?source=rss-db08db068da8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 02:04:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@esthersm/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ Building an Interactive Flip Card KPI Dashboard with Dash, Plotly & CSS]]></title>
            <link>https://medium.com/@esthersm/building-an-interactive-flip-card-kpi-dashboard-with-dash-plotly-css-6ad367b165f5?source=rss-db08db068da8------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ad367b165f5</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[plotly]]></category>
            <category><![CDATA[flip-card]]></category>
            <category><![CDATA[dashboard]]></category>
            <dc:creator><![CDATA[Esther]]></dc:creator>
            <pubDate>Sat, 11 Apr 2026 15:06:17 GMT</pubDate>
            <atom:updated>2026-04-11T16:25:07.633Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*IUMQ-lVKXugD8GFql3lxIA.gif" /></figure><p>I built a small KPI dashboard where the focus wasn’t on adding more charts, but on:</p><p>👉 <strong>clean structure, reusable components, and simple interaction</strong></p><p>The stack is minimal:</p><ul><li>Dash → app &amp; callbacks</li><li>Plotly → charts</li><li>CSS → interaction (flip animation)</li></ul><h3>🧠 1. Data Layer (Separated from UI)</h3><p>Instead of hardcoding values, the app reads from 4 example CSV files, this is the first:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*CaZmU5ds3SuhEBK0uS-x9A.png" /></figure><pre>from utils.data_reader import read_csv</pre><pre>_trend = read_csv(&quot;revenue_trend.csv&quot;)<br>REVENUE_LABELS = [r[&quot;month&quot;] for r in _trend]<br>REVENUE_VALUES = [int(r[&quot;value&quot;]) for r in _trend]</pre><p>👉 Why this matters:</p><ul><li>keeps UI clean</li><li>makes switching to API/database easy later</li><li>improves scalability</li></ul><h3>🎨 2. Consistent Chart System</h3><p>All charts share a base layout:</p><pre>def chart_base():<br>    return dict(<br>        template=&quot;plotly_dark&quot;,<br>        margin=dict(l=0, r=0, t=0, b=0),<br>        paper_bgcolor=&quot;rgba(0,0,0,0)&quot;,<br>        plot_bgcolor=&quot;rgba(0,0,0,0)&quot;,<br>        xaxis=dict(visible=False),<br>        yaxis=dict(visible=False),<br>        height=110,<br>    )</pre><p>👉 Result:</p><ul><li>consistent look</li><li>zero duplication</li><li>avoids Plotly layout mutation issues</li></ul><h3>📊 3. Layered Micro-Charts (Better UX)</h3><p>Instead of simple lines, the main chart uses <strong>two layers</strong>:</p><pre>fig.add_trace(go.Scatter(<br>    x=xs, y=data,<br>    fill=&quot;tozeroy&quot;,<br>    line=dict(width=0),<br>    fillcolor=hex_to_rgba(color, 0.25),<br>))</pre><pre>fig.add_trace(go.Scatter(<br>    x=xs, y=data,<br>    mode=&quot;lines+markers&quot;,<br>    line=dict(color=color, width=2),<br>))</pre><p>👉 This creates:</p><ul><li>depth</li><li>clearer trends</li><li>modern dashboard feel</li></ul><h3>🎴 4. Reusable Flip Card Component</h3><p>Each KPI is a reusable component:</p><pre>def flip_card(card_id, title, value, subtitle, back_fig, front_fig):<br>    return html.Div(<br>        className=&quot;flip-card&quot;,<br>        children=[<br>            html.Div(<br>                id=f&quot;{card_id}-inner&quot;,<br>                className=&quot;flip-card-inner&quot;,<br>                n_clicks=0,<br>                children=[front, back],<br>            )<br>        ],<br>    )</pre><p>👉 Structure:</p><ul><li>front → KPI + quick visual</li><li>back → detailed view</li><li>click → flip</li></ul><h3>🎨 5. CSS Handles the Interaction (No JS)</h3><p>The flip effect is entirely CSS-driven.</p><h3>Flip trigger</h3><pre>.flip-card-inner.flipped {<br>  transform: rotateY(180deg);<br>}</pre><h3>3D environment</h3><pre>.flip-card {<br>  perspective: 1000px;<br>}</pre><pre>.flip-card-inner {<br>  transform-style: preserve-3d;<br>  transition: transform 0.65s cubic-bezier(0.4, 0.2, 0.2, 1);<br>}</pre><h3>Hide reversed side</h3><pre>.flip-card-front,<br>.flip-card-back {<br>  backface-visibility: hidden;<br>}</pre><h3>Back side setup</h3><pre>.flip-card-back {<br>  transform: rotateY(180deg);<br>}</pre><p>👉 Result:</p><ul><li>smooth 3D animation</li><li>no JavaScript needed</li><li>clean separation of concerns</li></ul><h3>🔁 6. Minimal Backend Logic</h3><p>The interaction logic is intentionally simple:</p><pre>@app.callback(<br>    Output(&quot;c1-inner&quot;, &quot;className&quot;),<br>    Input(&quot;c1-inner&quot;, &quot;n_clicks&quot;),<br>)<br>def flip(n):<br>    return &quot;flip-card-inner flipped&quot; if n and n % 2 else &quot;flip-card-inner&quot;</pre><p>👉 Behavior:</p><ul><li>odd click → flipped</li><li>even click → reset</li></ul><h3>📦 7. Data-Driven UI</h3><p>Cards are defined as data:</p><pre>CARDS = [<br>    (<br>        &quot;c1&quot;, &quot;Revenue&quot;, &quot;€950K&quot;, &quot;↑ +12% vs last month&quot;,<br>        mini_area_line(REVENUE_VALUES, &quot;#818cf8&quot;, REVENUE_LABELS),<br>        mini_map(MAP_ISO3, MAP_VALUES, &quot;€Revenue&quot;, ...),<br>    ),<br>]</pre><p>👉 Benefits:</p><ul><li>scalable</li><li>reusable</li><li>easy to extend</li></ul><h3>🧱 8. Responsive Layout</h3><pre>dbc.Row(<br>    [dbc.Col(flip_card(*c), xs=12, sm=8, md=4) for c in CARDS],<br>)</pre><p>👉 Automatically adapts:</p><ul><li>mobile → 1 column</li><li>tablet → 2</li><li>desktop → 3</li></ul><h3>💡 Key Takeaways</h3><ul><li>Build <strong>components, not pages</strong></li><li>Use <strong>CSS for interaction whenever possible</strong></li><li>Keep charts <strong>minimal and contextual</strong></li><li>Separate <strong>data from presentation</strong></li></ul><h3>⚠️ Final Thought</h3><p>Most dashboards fail because they try to show everything.</p><p>👉 A better approach:</p><ul><li>show less</li><li>make it interactive</li><li>make it intuitive</li></ul><p>That’s what actually makes a dashboard usable.</p><p>Full structure and code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*wKzcixGTzOn_gLpXob9hUw.png" /></figure><p>app.py</p><pre>from dash import Dash, html, dcc, Input, Output  # Dash core components and callback tools<br>import dash_bootstrap_components as dbc            # Bootstrap UI components and themes<br>import plotly.graph_objects as go                  # low-level Plotly chart objects<br>from utils.data_reader import read_csv             # CSV helper from utils/<br><br><br># ── Load data from data/ ─────────────────────────────────────────<br><br>_trend = read_csv(&quot;revenue_trend.csv&quot;)             # monthly revenue trend<br>REVENUE_LABELS = [r[&quot;month&quot;]      for r in _trend] # month abbreviations (x-axis)<br>REVENUE_VALUES = [int(r[&quot;value&quot;]) for r in _trend] # revenue values (y-axis)<br><br>_map = read_csv(&quot;revenue_map.csv&quot;)                 # revenue by country<br>MAP_ISO3   = [r[&quot;iso3&quot;]        for r in _map]      # ISO-3 country codes<br>MAP_VALUES = [int(r[&quot;value&quot;])  for r in _map]      # corresponding values<br><br>_hbar = read_csv(&quot;profit_hbar.csv&quot;)                # profit by country<br>HBAR_COUNTRIES = [r[&quot;country&quot;]    for r in _hbar]  # country names<br>HBAR_VALUES    = [int(r[&quot;value&quot;]) for r in _hbar]  # profit values<br><br>_tbl = read_csv(&quot;profit_table.csv&quot;)                # profit breakdown by category<br>PROFIT_TABLE_HEADERS = list(_tbl[0].keys())        # header row from first dict&#39;s keys<br>PROFIT_TABLE_ROWS    = [tuple(r.values()) for r in _tbl]  # each row as a tuple<br><br><br># ── App init ─────────────────────────────────────────────────────<br><br>app = Dash(__name__, external_stylesheets=[dbc.themes.DARKLY])  # dark Bootstrap theme<br><br>TRANSPARENT = &quot;rgba(0,0,0,0)&quot;  # reusable transparent colour for chart backgrounds<br><br><br># ── Helpers ──────────────────────────────────────────────────────<br><br># Returns a fresh dict every call — Plotly mutates layout dicts in place<br>def chart_base():<br>    return dict(<br>        template=&quot;plotly_dark&quot;,<br>        margin=dict(l=0, r=0, t=0, b=0),<br>        paper_bgcolor=TRANSPARENT,<br>        plot_bgcolor=TRANSPARENT,<br>        xaxis=dict(visible=False),<br>        yaxis=dict(visible=False),<br>        height=110,<br>    )<br><br><br># Converts a hex colour string to rgba() for semi-transparent fills<br>def hex_to_rgba(hex_color, alpha=0.18):<br>    h = hex_color.lstrip(&quot;#&quot;)<br>    r, g, b = int(h[0:2], 16), int(h[2:4], 16), int(h[4:6], 16)<br>    return f&quot;rgba({r},{g},{b},{alpha})&quot;<br><br><br># ── Chart builders ───────────────────────────────────────────────<br><br># Two-layer chart: semi-transparent area fill + crisp line+marker trace on top<br>def mini_area_line(data, color, xlabels=None):<br>    xs = list(range(len(data)))<br>    layout = chart_base()<br>    if xlabels:<br>        layout[&quot;xaxis&quot;] = dict(<br>            visible=True,<br>            tickvals=xs,<br>            ticktext=xlabels,<br>            tickfont=dict(size=9, color=&quot;#888&quot;),<br>            showgrid=False,<br>            zeroline=False,<br>            range=[-0.5, len(xs) - 0.5],<br>        )<br>        layout[&quot;margin&quot;][&quot;b&quot;] = 20              # extra bottom margin for tick labels<br>    layout[&quot;showlegend&quot;] = False<br>    fig = go.Figure()<br>    fig.add_trace(go.Scatter(                   # layer 1 — fill only, line hidden<br>        x=xs, y=data,<br>        mode=&quot;lines&quot;,<br>        fill=&quot;tozeroy&quot;,<br>        line=dict(color=color, width=0),<br>        fillcolor=hex_to_rgba(color, 0.25),<br>        hoverinfo=&quot;skip&quot;,                       # layer 2 handles hover<br>    ))<br>    fig.add_trace(go.Scatter(                   # layer 2 — line+markers on top<br>        x=xs, y=data,<br>        mode=&quot;lines+markers&quot;,<br>        line=dict(color=color, width=2),<br>        marker=dict(size=5, color=color, line=dict(width=0)),<br>        customdata=xlabels or xs,<br>        hovertemplate=&quot;&lt;b&gt;%{customdata}&lt;/b&gt;&lt;br&gt;%{y}&lt;extra&gt;&lt;/extra&gt;&quot;,<br>    ))<br>    fig.update_layout(**layout)<br>    return fig<br><br><br># Plotly table with alternating row backgrounds<br>def mini_table(headers, rows):<br>    fig = go.Figure(go.Table(<br>        header=dict(<br>            values=headers,<br>            fill_color=&quot;#1a1a1a&quot;,<br>            font=dict(color=&quot;#888&quot;, size=9),<br>            align=&quot;left&quot;,<br>            line=dict(color=&quot;#2a2a2a&quot;, width=1),<br>            height=22,<br>        ),<br>        cells=dict(<br>            values=list(zip(*rows)),            # transpose rows → columns for Plotly Table<br>            fill_color=[&quot;#111&quot;, &quot;#0d0d0d&quot;] * (len(rows) // 2 + 1),<br>            font=dict(color=&quot;#ccc&quot;, size=10),<br>            align=&quot;left&quot;,<br>            line=dict(color=&quot;#1e1e1e&quot;, width=1),<br>            height=20,<br>        ),<br>    ))<br>    fig.update_layout(<br>        template=&quot;plotly_dark&quot;,<br>        paper_bgcolor=TRANSPARENT,<br>        plot_bgcolor=TRANSPARENT,<br>        height=160,<br>        margin=dict(l=0, r=0, t=0, b=0),<br>    )<br>    return fig<br><br><br># Choropleth map scoped to Europe, coloured by metric value<br>def mini_map(iso3, values, label, colorscale):<br>    fig = go.Figure(go.Choropleth(<br>        locations=iso3,<br>        z=values,<br>        colorscale=colorscale,<br>        showscale=False,<br>        marker=dict(line=dict(color=&quot;#222&quot;, width=0.5)),<br>        hovertemplate=&quot;&lt;b&gt;%{location}&lt;/b&gt;&lt;br&gt;&quot; + label + &quot;: %{z}K&lt;extra&gt;&lt;/extra&gt;&quot;,<br>    ))<br>    fig.update_layout(<br>        template=&quot;plotly_dark&quot;,<br>        paper_bgcolor=TRANSPARENT,<br>        plot_bgcolor=TRANSPARENT,<br>        height=140,<br>        margin=dict(l=0, r=0, t=0, b=0),<br>        geo=dict(<br>            scope=&quot;europe&quot;,<br>            bgcolor=TRANSPARENT,<br>            showframe=False,<br>            showcoastlines=False,<br>            showland=True,  landcolor=&quot;#1a1a1a&quot;,<br>            showocean=True, oceancolor=TRANSPARENT,<br>            showcountries=True, countrycolor=&quot;#2a2a2a&quot;,<br>            projection_type=&quot;natural earth&quot;,<br>        ),<br>    )<br>    return fig<br><br><br># Horizontal bar chart — first country in list appears at the top<br>def country_hbar(countries, values, color):<br>    fig = go.Figure(go.Bar(<br>        x=values,<br>        y=countries,<br>        orientation=&quot;h&quot;,<br>        marker=dict(color=color, opacity=0.8, line=dict(width=0)),<br>        hovertemplate=&quot;&lt;b&gt;%{y}&lt;/b&gt;&lt;br&gt;€%{x}K&lt;extra&gt;&lt;/extra&gt;&quot;,<br>    ))<br>    fig.update_layout(<br>        template=&quot;plotly_dark&quot;,<br>        paper_bgcolor=TRANSPARENT,<br>        plot_bgcolor=TRANSPARENT,<br>        height=160,<br>        margin=dict(l=0, r=4, t=4, b=0),<br>        xaxis=dict(visible=False),              # bar length is self-evident<br>        yaxis=dict(<br>            visible=True,<br>            tickfont=dict(size=9, color=&quot;#888&quot;),<br>            showgrid=False,<br>            zeroline=False,<br>            autorange=&quot;reversed&quot;,               # top country = first in list<br>        ),<br>    )<br>    return fig<br><br><br># ── Flip card builder ────────────────────────────────────────────<br><br># Builds a 3-D flip card — front shows KPI+chart, back shows trend on click<br>def flip_card(card_id, title, value, subtitle, back_fig, front_fig):<br>    arrow = &quot;↑&quot; if &quot;↑&quot; in subtitle else (&quot;↓&quot; if &quot;↓&quot; in subtitle else &quot;→&quot;)<br>    badge_color = &quot;success&quot; if arrow == &quot;↑&quot; else (&quot;danger&quot; if arrow == &quot;↓&quot; else &quot;secondary&quot;)<br><br>    badge = dbc.Badge(<br>        [arrow, &quot; &quot;, subtitle.lstrip(&quot;↑↓→ &quot;)],  # arrow + text e.g. &quot;+12% vs last month&quot;<br>        color=badge_color,<br>        pill=True,<br>        style={&quot;fontSize&quot;: &quot;9px&quot;, &quot;fontWeight&quot;: &quot;600&quot;},<br>    )<br><br>    title_row = dbc.Stack(                       # title and badge on opposite ends<br>        [<br>            html.Span(title, style={<br>                &quot;fontSize&quot;: &quot;11px&quot;, &quot;color&quot;: &quot;#666&quot;,<br>                &quot;textTransform&quot;: &quot;uppercase&quot;, &quot;letterSpacing&quot;: &quot;0.08em&quot;,<br>            }),<br>            badge,<br>        ],<br>        direction=&quot;horizontal&quot;,<br>        className=&quot;justify-content-between align-items-center&quot;,<br>    )<br><br>    front = html.Div(                            # front face — KPI value + chart<br>        className=&quot;flip-card-front&quot;,<br>        children=[<br>            title_row,<br>            html.Div(value, className=&quot;card-value&quot;),<br>            dcc.Graph(<br>                figure=front_fig,<br>                config={&quot;displayModeBar&quot;: False},<br>                style={&quot;flex&quot;: &quot;1&quot;, &quot;marginTop&quot;: &quot;4px&quot;},<br>            ),<br>        ],<br>    )<br><br>    back = html.Div(                             # back face — revealed after click<br>        className=&quot;flip-card-back&quot;,<br>        children=[<br>            title_row,<br>            dcc.Graph(<br>                figure=back_fig,<br>                config={&quot;displayModeBar&quot;: False},<br>                style={&quot;flex&quot;: &quot;1&quot;, &quot;marginTop&quot;: &quot;8px&quot;},<br>            ),<br>        ],<br>    )<br><br>    return html.Div(                             # outer div = 3-D stage<br>        className=&quot;flip-card&quot;,<br>        children=[<br>            html.Div(                            # inner div = rotating element<br>                id=f&quot;{card_id}-inner&quot;,<br>                className=&quot;flip-card-inner&quot;,<br>                n_clicks=0,<br>                children=[front, back],<br>            )<br>        ],<br>    )<br><br><br># ── KPI card data ────────────────────────────────────────────────<br># Tuple order: (card_id, title, value, subtitle, back_fig, front_fig)<br><br>CARDS = [<br>    (<br>        &quot;c1&quot;, &quot;Revenue&quot;, &quot;€950K&quot;, &quot;↑ +12% vs last month&quot;,<br>        mini_area_line(REVENUE_VALUES, &quot;#818cf8&quot;, REVENUE_LABELS),  # back: monthly trend<br>        mini_map(MAP_ISO3, MAP_VALUES, &quot;€Revenue&quot;, [[0, &quot;#1a1030&quot;], [1, &quot;#818cf8&quot;]]),  # front: map<br>    ),<br>    (<br>        &quot;c2&quot;, &quot;Gross Profit&quot;, &quot;€260K&quot;, &quot;↑ Stable margin&quot;,<br>        mini_table(PROFIT_TABLE_HEADERS, PROFIT_TABLE_ROWS),        # back: breakdown table<br>        country_hbar(HBAR_COUNTRIES, HBAR_VALUES, &quot;#fb923c&quot;),       # front: horizontal bar<br>    ),<br>]<br><br><br># ── Layout ───────────────────────────────────────────────────────<br><br>app.layout = dbc.Container(<br>    [<br>        html.Div(&quot;KPI Dashboard&quot;, style={        # page title<br>            &quot;textAlign&quot;: &quot;center&quot;, &quot;color&quot;: &quot;#f0f0f0&quot;,<br>            &quot;fontSize&quot;: &quot;18px&quot;, &quot;fontWeight&quot;: &quot;600&quot;,<br>            &quot;letterSpacing&quot;: &quot;0.05em&quot;, &quot;textTransform&quot;: &quot;uppercase&quot;,<br>            &quot;marginTop&quot;: &quot;32px&quot;, &quot;marginBottom&quot;: &quot;4px&quot;,<br>        }),<br>        html.Div(&quot;Click a card to see the trend&quot;, style={  # subtitle hint<br>            &quot;textAlign&quot;: &quot;center&quot;, &quot;color&quot;: &quot;#444&quot;,<br>            &quot;fontSize&quot;: &quot;11px&quot;, &quot;marginBottom&quot;: &quot;40px&quot;,<br>        }),<br>        dbc.Row(<br>            [dbc.Col(flip_card(*c), xs=12, sm=8, md=4) for c in CARDS],  # one card per column<br>            justify=&quot;center&quot;,<br>            className=&quot;g-3 pb-5&quot;,<br>        ),<br>    ],<br>    fluid=True,                                  # full-width, no max-width cap<br>)<br><br><br># ── Flip callback ────────────────────────────────────────────────<br><br># Odd click count → flipped (back visible); even → front visible<br>@app.callback(<br>    *[Output(f&quot;c{i}-inner&quot;, &quot;className&quot;) for i in range(1, len(CARDS) + 1)],  # one output per card<br>    *[Input(f&quot;c{i}-inner&quot;, &quot;n_clicks&quot;)  for i in range(1, len(CARDS) + 1)],  # one input per card<br>)<br>def flip(*clicks):<br>    return [<br>        &quot;flip-card-inner flipped&quot; if n and n % 2 == 1 else &quot;flip-card-inner&quot;<br>        for n in clicks<br>    ]<br><br><br>if __name__ == &quot;__main__&quot;:<br>    app.run(debug=True)  # debug=True enables hot reload and error overlay</pre><p>style.css:</p><pre>/* ── Global ─────────────────────────────────────────────────────── */<br>body, .container-fluid {<br>  background-color: #474343 !important;<br>}<br><br>/* ── Flip card stage ─────────────────────────────────────────────<br>   perspective creates the 3-D depth for the rotation effect       */<br>.flip-card {<br>  width: 100%;<br>  height: 260px;<br>  perspective: 1000px;<br>}<br><br>/* ── Rotating element ────────────────────────────────────────────<br>   preserve-3d keeps front/back in the same 3-D space;<br>   transition drives the smooth flip animation                     */<br>.flip-card-inner {<br>  position: relative;<br>  width: 100%;<br>  height: 100%;<br>  transition: transform 0.65s cubic-bezier(0.4, 0.2, 0.2, 1);<br>  transform-style: preserve-3d;<br>  cursor: pointer;<br>}<br><br>/* flipped class toggled by the Dash callback on click             */<br>.flip-card-inner.flipped {<br>  transform: rotateY(180deg);<br>}<br><br>/* ── Front &amp; back shared styles ─────────────────────────────────<br>   backface-visibility: hidden hides the face when it is rotated<br>   180 ° away from the viewer                                      */<br>.flip-card-front,<br>.flip-card-back {<br>  position: absolute;<br>  width: 100%;<br>  height: 100%;<br>  border-radius: 16px;<br>  border: 1px solid #2a2a2a;<br>  box-shadow: none !important;<br>  backface-visibility: hidden;<br>  padding: 18px 20px;<br>  display: flex;<br>  flex-direction: column;<br>  gap: 10px;<br>}<br><br>.flip-card-front {<br>  background: linear-gradient(160deg, #222 0%, #1a1a1a 100%);<br>}<br><br>/* back face is pre-rotated 180 ° so it appears correct after flip */<br>.flip-card-back {<br>  background: #1c1c1c;<br>  transform: rotateY(180deg);<br>}<br><br>/* subtle border highlight on hover                                */<br>.flip-card-inner:hover .flip-card-front,<br>.flip-card-inner:hover .flip-card-back {<br>  border-color: #3a3a3a;<br>}<br><br>/* ── Typography ─────────────────────────────────────────────────── */<br>.card-title {<br>  color: #666;<br>  font-size: 11px;<br>  text-transform: uppercase;<br>  letter-spacing: 0.08em;<br>  font-weight: 500;<br>}<br><br>.card-value {<br>  font-size: 32px;<br>  color: #f0f0f0;<br>  font-weight: 700;<br>  letter-spacing: -0.02em;<br>  line-height: 1;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ad367b165f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How can you improve the appearance of your chart in Plotly?]]></title>
            <link>https://medium.com/@esthersm/how-can-you-improve-the-appearance-of-your-chart-in-plotly-ad14230270ca?source=rss-db08db068da8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad14230270ca</guid>
            <category><![CDATA[plotly]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Esther]]></dc:creator>
            <pubDate>Tue, 07 Apr 2026 16:27:55 GMT</pubDate>
            <atom:updated>2026-04-07T16:27:55.886Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xst_ZCUl65ZDA9oG5PpmkA.png" /><figcaption>Image by Author with Plotly</figcaption></figure><p>Most Plotly charts look like they were slapped together in five minutes. They’re usually cluttered, inconsistent, and — honestly — pretty painful to read.</p><p>The issue isn’t the library itself; Plotly is powerful. The problem is how we use it.</p><p>If you want your visuals to actually look professional and provide real value, here are 10 practical ways to level up your charts instantly.</p><h3>1. Ditch the Default Theme</h3><p>Nothing says “I just started learning Python” like the default gray background. It looks like a prototype, not a finished product.</p><blockquote><em>fig.update_layout(template=&quot;plotly_white&quot;)</em></blockquote><p>Pick a clean, minimal theme and stick with it. It makes a world of difference.</p><h3>2. Kill the Gridline Noise</h3><p>If everything is highlighted, nothing is. Excessive gridlines just create visual static.</p><blockquote><em>fig.update_layout(xaxis_showgrid=False, yaxis_showgrid=False)</em></blockquote><p>Strip away the noise so your data can actually stand out.</p><h3>3. Stop Using Random Colors</h3><p>Color shouldn’t just be “decoration.” If you’re using 10 different colors for no reason, you’re confusing your audience. Use color to encode meaning — like categories, status, or importance — not just because it looks pretty.</p><h3>4. Write a Title That Actually Says Something</h3><p>“Sales Chart” is a lazy title. It tells me nothing.</p><blockquote><em>fig.update_layout(title=&quot;Monthly Revenue Growth (2024–2025)&quot;, title_x=0.5)</em></blockquote><p>A great title explains the <strong>insight</strong>, not just the data source.</p><h3>5. Clean Up Your Hover Tooltips</h3><p>The default hover labels are usually a mess of raw data.</p><blockquote><em>fig.update_traces(hovertemplate=&quot;Revenue: %{y}&lt;extra&gt;&lt;/extra&gt;&quot;)</em></blockquote><p>Curate what the user sees. Show less, but make it mean more.</p><h3>6. Fix Your Typography</h3><p>Inconsistent fonts are a silent credibility killer. If your titles and labels are all over the place, it looks amateur.</p><blockquote><em>fig.update_layout(font=dict(size=14), title_font=dict(size=20))</em></blockquote><p>Consistency builds trust. Period.</p><h3>7. Give Your Data Room to Breathe</h3><p>Cramped charts are hard to process. If your labels are touching the edges, you’ve failed at hierarchy.</p><blockquote><em>fig.update_layout(margin=dict(l=40, r=40, t=60, b=40))</em></blockquote><p>A little white space goes a long way.</p><h3>8. Use Highlighting to Tell a Story</h3><p>If every data point looks identical, the user doesn’t know where to look. Use opacity or bold colors to draw the eye to the specific trend or outlier that actually matters.</p><h3>9. Add Context (Don’t Make People Guess)</h3><p>A chart without an explanation is just a shape. If there’s a massive spike or a sudden drop, tell the user why.</p><blockquote><em>fig.add_annotation(x=2020, y=100, text=&quot;Market Crash&quot;, showarrow=True)</em></blockquote><p>Don’t just show the data — tell the story behind it.</p><h3>10. Design for the Human on the Other Side</h3><p>Before you hit “save,” ask yourself:</p><ul><li>What is the very first thing they should notice?</li><li>What decision does this chart help them make?</li><li>What can I delete without losing the message?</li></ul><h3>The Bottom Line</h3><p>A bad chart isn’t usually a coding error; it’s a design error. When you start thinking like a designer instead of just a developer, your work will instantly stand out.</p><p>Go back to one of your old projects today and apply just three of these rules. You’ll be shocked at how much better it looks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad14230270ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an Interactive Choropleth Map with Plotly.js and HTML]]></title>
            <link>https://medium.com/microsoft-power-bi/building-an-interactive-choropleth-map-with-plotly-js-and-html-65f846163b1b?source=rss-db08db068da8------2</link>
            <guid isPermaLink="false">https://medium.com/p/65f846163b1b</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[power-bi]]></category>
            <category><![CDATA[power-bi-tutorials]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Esther]]></dc:creator>
            <pubDate>Mon, 06 Apr 2026 13:03:32 GMT</pubDate>
            <atom:updated>2026-04-09T16:50:29.321Z</atom:updated>
            <content:encoded><![CDATA[<h3>🌍Building an Interactive Choropleth Map in Power BI with Plotly.js</h3><h4>- Turning Power BI into a Web App</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*3Uc8EFW1igSYK2vJNLtAsg.png" /><figcaption>Image by Author with Bootstrap dropdowns and Power BI slicers</figcaption></figure><p>Power BI is a strong tool out of the box, but at some point you start feeling the limits of its native visuals, especially when you want tighter control over <strong>interaction</strong>, <strong>styling</strong>, and overall <strong>user experience</strong>. This is exactly where combining the <strong>HTML Content Visual</strong>, <strong>Plotly.js</strong>, and <strong>Bootstrap</strong> becomes a powerful approach, allowing you to move beyond standard dashboards and create something that behaves more like a lightweight web application embedded inside Power BI.</p><p>In this example, the goal was to build a <strong>choropleth world map</strong> that is not only visually appealing but also highly <strong>interactive</strong>. The user can dynamically switch between <strong>metrics</strong>, change <strong>color scales</strong>, and alter the <strong>map projection</strong>, all within a single visual without relying on multiple report elements.</p><p><strong>🎁 </strong><a href="https://powerbi-masterclass.short.gy/learning-database?utm_source=medium&amp;utm_medium=medium-post&amp;utm_campaign=database-medium-post-start"><strong>Get friend links for all of our 1500&gt; Power BI learning articles here</strong></a><strong> 🎁</strong></p><h3>From DAX to JavaScript: Bridging Two Worlds</h3><p>The most important conceptual step in this solution is understanding that <strong>Power BI</strong> and <strong>JavaScript</strong> operate in completely different environments, so the data must be transformed into a format that the browser can interpret. This is achieved by generating <strong>JSON-like structures</strong> directly in <strong>DAX</strong>, which are then injected into the HTML string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*b0S7GsLofCW91FkRgnZYMA.png" /><figcaption>Bootstrap dropdowns</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*882eTn8AVA5uT8qk1czVNA.png" /><figcaption>Power BI Slicers</figcaption></figure><p>The model aggregates data at the <strong>country level</strong>, calculating both <strong>Revenue</strong> and <strong>Deal Count</strong>, ensuring that the visualization has flexible inputs.</p><pre>VAR MapRevenue =<br>SUMMARIZE(<br>    DimCompany,<br>    DimCompany[Country],<br>    &quot;value&quot;, CALCULATE(SUM(FactDeals[DealValueEUR]))<br>)</pre><pre>VAR MapDeals =<br>SUMMARIZE(<br>    DimCompany,<br>    DimCompany[Country],<br>    &quot;value&quot;, CALCULATE(COUNT(FactDeals[DealID]))<br>)</pre><p>Once the aggregation is complete, the values are serialized into <strong>JSON arrays</strong> using CONCATENATEX, effectively converting tabular data into something that can be consumed by <strong>Plotly.js</strong>.</p><pre>VAR CountryJSON =<br>&quot;[&quot; &amp;<br>CONCATENATEX(<br>    MapRevenue,<br>    &quot;&quot;&quot;&quot; &amp; DimCompany[Country] &amp; &quot;&quot;&quot;&quot;,<br>    &quot;,&quot;<br>) &amp;<br>&quot;]&quot;</pre><p>This step is critical, because it forms the bridge between the <strong>data model</strong> and the <strong>front-end rendering layer</strong>.</p><h3>Designing the UI with Bootstrap</h3><p>Instead of relying entirely on Power BI slicers, a compact <strong>control panel</strong> is embedded directly into the visual using <strong>Bootstrap</strong>. This makes the interaction feel much more immediate and keeps the controls visually tied to the chart itself.</p><p>The dropdowns allow switching between:</p><ul><li><strong>metrics</strong> (Revenue vs Deal Count)</li><li><strong>color scales</strong> (Viridis, Blues, etc.)</li><li><strong>map projections</strong> (Natural Earth, Mercator, etc.)</li></ul><pre>&lt;select id=&#39;metricSelect&#39; class=&#39;form-select form-select-sm&#39;&gt;<br>  &lt;option value=&#39;revenue&#39;&gt;Revenue&lt;/option&gt;<br>  &lt;option value=&#39;deals&#39;&gt;Deal Count&lt;/option&gt;<br>&lt;/select&gt;</pre><p>This approach improves usability significantly, because it reduces reliance on external report elements and keeps everything self-contained.</p><h3>Rendering the Map with Plotly.js</h3><p>Once the data is available as <strong>JavaScript variables</strong>, <strong>Plotly.js</strong> handles the visualization. The map is generated dynamically using a reusable function that reacts to user selections.</p><pre>function drawMap(metric, scale, projection){<br><br>var values = revenue;<br>  if(metric === &#39;deals&#39;){<br>    values = deals;<br>  }<br>  var data = [{<br>    type:&#39;choropleth&#39;,<br>    locations:countries,<br>    locationmode:&#39;country names&#39;,<br>    z:values,<br>    colorscale:scale<br>  }];<br>  var layout = {<br>    geo:{<br>      projection:{type:projection}<br>    },<br>    margin:{t:0,l:0,r:0,b:0}<br>  };<br>  Plotly.newPlot(&#39;map&#39;, data, layout);<br>}</pre><p>The key idea here is that <strong>one function controls everything</strong>, making the visualization easy to maintain and extend.</p><h3>Adding Real Interactivity</h3><p>The interactivity layer is implemented using standard <strong>event listeners</strong>, which respond to user input and trigger a redraw of the map. This creates a smooth and responsive experience without requiring multiple visuals or complex Power BI configurations.</p><pre>function redraw(){<br><br>var metric = document.getElementById(&#39;metricSelect&#39;).value;<br>  var scale = document.getElementById(&#39;colorScale&#39;).value;<br>  var projection = document.getElementById(&#39;projectionSelect&#39;).value;<br>  drawMap(metric, scale, projection);<br>}</pre><p>This pattern effectively turns the visual into a <strong>state-driven component</strong>, similar to how modern web applications behave.</p><h3>Why This Approach Matters</h3><p>It would be inaccurate to claim that this replaces native visuals entirely, because Power BI’s built-in tools are often faster and easier for standard reporting. However, when the requirement shifts toward <strong>custom interaction</strong>, <strong>advanced styling</strong>, or <strong>storytelling</strong>, this approach becomes significantly more powerful.</p><p>What you gain is full <strong>control</strong> over how the visualization behaves, while still leveraging Power BI’s <strong>data model</strong>, <strong>filters</strong>, and <strong>performance engine</strong>. This combination allows you to push beyond the usual limitations without abandoning the platform.</p><p>Full code:</p><pre>HTML_Choropleth_Map = <br><br>VAR MapRevenue =<br>SUMMARIZE(<br>    DimCompany,<br>    DimCompany[Country],<br>    &quot;value&quot;, CALCULATE(SUM(FactDeals[DealValueEUR]))<br>)<br><br>VAR MapDeals =<br>SUMMARIZE(<br>    DimCompany,<br>    DimCompany[Country],<br>    &quot;value&quot;, CALCULATE(COUNT(FactDeals[DealID]))<br>)<br><br>VAR CountryJSON =<br>&quot;[&quot; &amp;<br>CONCATENATEX(<br>    MapRevenue,<br>    &quot;&quot;&quot;&quot; &amp; DimCompany[Country] &amp; &quot;&quot;&quot;&quot;,<br>    &quot;,&quot;<br>) &amp;<br>&quot;]&quot;<br><br>VAR RevenueJSON =<br>&quot;[&quot; &amp;<br>CONCATENATEX(<br>    MapRevenue,<br>    [value],<br>    &quot;,&quot;<br>) &amp;<br>&quot;]&quot;<br><br>VAR DealsJSON =<br>&quot;[&quot; &amp;<br>CONCATENATEX(<br>    MapDeals,<br>    [value],<br>    &quot;,&quot;<br>) &amp;<br>&quot;]&quot;<br><br>RETURN<br><br>&quot;<br>&lt;link href=&#39;https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css&#39; rel=&#39;stylesheet&#39;&gt;<br><br>&lt;div class=&#39;container-fluid&#39; style=&#39;font-family:Segoe UI&#39;&gt;<br><br>&lt;div class=&#39;row mb-4&#39;&gt;<br><br>&lt;div class=&#39;col-auto&#39;&gt;<br><br>&lt;select id=&#39;metricSelect&#39; class=&#39;form-select form-select-sm&#39;&gt;<br>&lt;option value=&#39;revenue&#39;&gt;Revenue&lt;/option&gt;<br>&lt;option value=&#39;deals&#39;&gt;Deal Count&lt;/option&gt;<br>&lt;/select&gt;<br><br>&lt;/div&gt;<br><br>&lt;div class=&#39;col-auto&#39;&gt;<br><br>&lt;select id=&#39;colorScale&#39; class=&#39;form-select form-select-sm&#39;&gt;<br>&lt;option value=&#39;Viridis&#39;&gt;Viridis&lt;/option&gt;<br>&lt;option value=&#39;Blues&#39;&gt;Blues&lt;/option&gt;<br>&lt;option value=&#39;YlOrRd&#39;&gt;YlOrRd&lt;/option&gt;<br>&lt;option value=&#39;Cividis&#39;&gt;Cividis&lt;/option&gt;<br>&lt;option value=&#39;Portland&#39;&gt;Portland&lt;/option&gt;<br>&lt;/select&gt;<br><br>&lt;/div&gt;<br><br>&lt;div class=&#39;col-auto&#39;&gt;<br><br>&lt;select id=&#39;projectionSelect&#39; class=&#39;form-select form-select-sm&#39;&gt;<br>&lt;option value=&#39;natural earth&#39;&gt;Natural Earth&lt;/option&gt;<br>&lt;option value=&#39;equirectangular&#39;&gt;Equirectangular&lt;/option&gt;<br>&lt;option value=&#39;mercator&#39;&gt;Mercator&lt;/option&gt;<br>&lt;/select&gt;<br><br>&lt;/div&gt;<br><br>&lt;/div&gt;<br><br>&lt;div style=&#39;height:40px&#39;&gt;&lt;/div&gt;<br><br>&lt;div class=&#39;row&#39;&gt;<br>&lt;div class=&#39;col-md-12&#39;&gt;<br>&lt;div id=&#39;map&#39; style=&#39;height:600px&#39;&gt;&lt;/div&gt;<br>&lt;/div&gt;<br>&lt;/div&gt;<br><br>&lt;/div&gt;<br><br>&lt;script src=&#39;https://cdn.plot.ly/plotly-latest.min.js&#39;&gt;&lt;/script&gt;<br><br>&lt;script&gt;<br><br>var countries = &quot; &amp; CountryJSON &amp; &quot;;<br>var revenue = &quot; &amp; RevenueJSON &amp; &quot;;<br>var deals = &quot; &amp; DealsJSON &amp; &quot;;<br><br>function drawMap(metric,scale,projection){<br><br>var values = revenue<br><br>if(metric === &#39;deals&#39;){<br>values = deals<br>}<br><br>var data=[{<br>type:&#39;choropleth&#39;,<br>locations:countries,<br>locationmode:&#39;country names&#39;,<br>z:values,<br>colorscale:scale<br>}]<br><br>var layout={<br>geo:{<br>projection:{type:projection}<br>},<br>margin:{t:0,l:0,r:0,b:0}<br>}<br><br>Plotly.newPlot(&#39;map&#39;,data,layout)<br><br>}<br><br>drawMap(&#39;revenue&#39;,&#39;Viridis&#39;,&#39;natural earth&#39;)<br><br>function redraw(){<br><br>var metric=document.getElementById(&#39;metricSelect&#39;).value<br>var scale=document.getElementById(&#39;colorScale&#39;).value<br>var projection=document.getElementById(&#39;projectionSelect&#39;).value<br><br>drawMap(metric,scale,projection)<br><br>}<br><br>document.getElementById(&#39;metricSelect&#39;).addEventListener(&#39;change&#39;,redraw)<br>document.getElementById(&#39;colorScale&#39;).addEventListener(&#39;change&#39;,redraw)<br>document.getElementById(&#39;projectionSelect&#39;).addEventListener(&#39;change&#39;,redraw)<br><br>&lt;/script&gt;<br>&quot;</pre><h3>Final Thoughts</h3><p>This solution sits at the intersection of <strong>Business Intelligence</strong> and <strong>front-end development</strong>, and that is exactly why it is so effective. By combining <strong>DAX</strong> for data transformation, <strong>HTML + Bootstrap</strong> for layout, and <strong>Plotly.js</strong> for rendering, you extend Power BI into something far more flexible than a traditional reporting tool.</p><p>If you continue in this direction, you can introduce <strong>custom tooltips</strong>, <strong>animations</strong>, or even more complex <strong>user interactions</strong>, turning your reports into fully interactive data applications.</p><p><strong>💡 </strong><a href="https://powerbi-masterclass.short.gy/pbi-gpt?utm_source=medium&amp;utm_campaign=pbi-gpt-medium-post-end"><strong>MUST TRY — Power BI GPT — Personal Power BI Learning Coach</strong></a><strong>💡</strong></p><blockquote>Don’t forget to subscribe to</blockquote><blockquote>👉 <a href="https://powerbi-masterclass.short.gy/publication?utm_source=medium&amp;utm_medium=medium-post&amp;utm_campaign=publication-medium-post-end">Power BI Publication</a></blockquote><blockquote>👉 <a href="https://powerbi-masterclass.short.gy/newsletter-medium?utm_source=medium&amp;utm_medium=medium-post&amp;utm_campaign=newsletter-medium-medium-post-end">Power BI Newsletter</a></blockquote><blockquote>and join our Power BI community:</blockquote><p><a href="https://linktr.ee/powerbi.masterclass?utm_source=medium&amp;utm_medium=medium-post&amp;utm_campaign=linktree-medium-post-end&amp;source=post_page-----ac05a5b57401---------------------------------------">Microsoft Power BI Masterclass | Linktree</a></p><p><strong>Power BI Masterclass Article Classification</strong></p><p><strong>Level:</strong> Intermediate</p><p><strong>Category:</strong> Data Visualization</p><p><strong>Tags:</strong> Tutorial, Data Visualization</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65f846163b1b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft-power-bi/building-an-interactive-choropleth-map-with-plotly-js-and-html-65f846163b1b">Building an Interactive Choropleth Map with Plotly.js and HTML</a> was originally published in <a href="https://medium.com/microsoft-power-bi">Power BI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Built a Calendar Heatmap in Power BI with Plotly.js]]></title>
            <link>https://medium.com/microsoft-power-bi/how-i-built-a-github-style-calendar-heatmap-in-power-bi-c602c6d98454?source=rss-db08db068da8------2</link>
            <guid isPermaLink="false">https://medium.com/p/c602c6d98454</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[power-bi-tutorials]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[power-bi]]></category>
            <dc:creator><![CDATA[Esther]]></dc:creator>
            <pubDate>Thu, 02 Apr 2026 13:06:25 GMT</pubDate>
            <atom:updated>2026-04-03T09:14:51.740Z</atom:updated>
            <content:encoded><![CDATA[<h4>Plotly.js chart Changed How I Look at Data</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FPVFmhZYl3Pgd7lonTlBTQ.png" /><figcaption>Plotly.js in Power BI — image by Author</figcaption></figure><p>I’ve always liked how GitHub visualizes activity. That simple grid of colored squares somehow tells a story instantly — when you were productive, when things slowed down, and where patterns start to emerge without forcing you to dig through numbers.</p><p>So I decided to recreate that experience inside Power BI.</p><p>What you see in the image above is my own implementation of a <strong>GitHub-style calendar heatmap</strong>, built using a mix of DAX, HTML, JavaScript, and Plotly.</p><p><strong>🎁 </strong><a href="https://powerbi-masterclass.short.gy/learning-database?utm_source=medium&amp;utm_medium=medium-post&amp;utm_campaign=database-medium-post-start"><strong>Get friend links for all of our 1500&gt; Power BI learning articles here</strong></a><strong> 🎁</strong></p><h3>What I see when I look at this chart</h3><p>At first glance, it’s just a grid. But once you understand the structure, it becomes surprisingly expressive.</p><ul><li>Along the bottom, I mapped <strong>week numbers</strong>, covering the full year.</li><li>On the left, you see the <strong>days of the week</strong>, from Monday to Sunday.</li><li>Each square represents a <strong>single day</strong>, and the color reflects how “active” that day was.</li></ul><p>I used the <strong>Viridis color scale</strong>, which I’ve grown to appreciate because it’s both readable and visually balanced:</p><ul><li>Darker purple tones signal quieter days</li><li>Greens and yellows highlight spikes in activity</li></ul><p>What I like most is that I don’t need exact values anymore. I can <em>feel</em> the data.</p><h3>The story hidden in the colors</h3><p>When I step back and look at the full heatmap, a few things immediately stand out to me:</p><ul><li>The <strong>beginning of the year</strong> feels energetic — lots of brighter colors, more consistency.</li><li>Then there’s a noticeable <strong>dip in the middle</strong>, where darker tones take over. That’s a signal I wouldn’t catch as quickly in a table.</li><li>Toward the <strong>end of the year</strong>, things become uneven — a mix of highs and lows, less predictable.</li></ul><p>This is exactly why I built it. Not for decoration, but for <strong>pattern recognition</strong>.</p><h3>Why I didn’t settle for native visuals</h3><p>Power BI is great, but it doesn’t natively support this type of calendar heatmap in a flexible way.</p><p>I had two options:</p><ul><li>Settle for something “close enough”</li><li>Or build exactly what I want</li></ul><h3>🛠️How I created it — step by step</h3><h4>Step 1 — Turning data into something JavaScript code</h4><p>I started in DAX by reshaping my dataset into a JSON-like structure:</p><pre>VAR JsonData =<br>    CONCATENATEX(<br>        calendar_3years_2022_2024,<br>        &quot;{date:&#39;&quot; &amp;<br>        FORMAT(calendar_3years_2022_2024[Date], &quot;yyyy-mm-dd&quot;) &amp;<br>        &quot;&#39;,value:&quot; &amp;<br>        calendar_3years_2022_2024[Value] &amp;<br>        &quot;}&quot;,<br>        &quot;,&quot;<br>    )</pre><p>This was the bridge between Power BI and the web world.</p><p>I load Plotly dynamically from a CDN, which makes the solution self-contained and ensures it works reliably inside the Power BI HTML Content visual.</p><h4>Step 2 — Making time “grid-friendly”</h4><p>JavaScript doesn’t think in weeks the way we need here, so I had to explicitly calculate:</p><ul><li>The <strong>ISO week number</strong></li><li>The <strong>day index (Monday → Sunday)</strong></li></ul><p>That step is critical — without it, the heatmap falls apart.</p><h4>Step 3 — Building the matrix</h4><p>I created a 7×53 structure — one row per weekday, one column per week:</p><pre>var z =<br>    Array.from({length: days},<br>        () =&gt; Array(weeks).fill(null)<br>    );</pre><p>Then I filled it with values, placing each day exactly where it belongs.</p><p>This is where the visualization really takes shape.</p><h4>Step 4 — Letting Plotly do its thing</h4><p>Finally, I used Plotly to render everything:</p><pre>var trace = {<br>    type: &#39;heatmap&#39;,<br>    z: z,<br>    x: Array.from({length: weeks},(_,i)=&gt;i+1),<br>    y: [<br>        &#39;Monday&#39;,&#39;Tuesday&#39;,&#39;Wednesday&#39;,<br>        &#39;Thursday&#39;,&#39;Friday&#39;,&#39;Saturday&#39;,&#39;Sunday&#39;<br>    ],<br>    colorscale: &#39;Viridis&#39; //Blues, Reds or RdYlGn or many more<br>};</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Jxh4rCczZq4ktQNqAomvg.png" /><figcaption>Blues Colorscales — image by Author</figcaption></figure><p>I chose the Viridis color scale because it’s clean and perceptually balanced, but it can easily be replaced with other palettes depending on your needs. For example, you might use <em>Blues</em> for a softer, more minimal look, <em>RdYlGn</em> to clearly highlight low vs. high values, or even a custom color scale to match your company’s branding.</p><p>And just like that — the data became something I could actually <em>read</em> at a glance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*heljmgRlbNyKXf17j9pJUg.gif" /><figcaption>Plotly.js heatmap and Power BI slicers</figcaption></figure><p>Full code:</p><pre>GitHub Heatmap HTML = <br><br>// Convert the table into a JSON-like string that JavaScript can read<br>VAR JsonData =<br>    CONCATENATEX(<br>        calendar_3years_2022_2024,<br>        &quot;{date:&#39;&quot; &amp;<br>        FORMAT(calendar_3years_2022_2024[Date], &quot;yyyy-mm-dd&quot;) &amp;<br>        &quot;&#39;,value:&quot; &amp;<br>        calendar_3years_2022_2024[Value] &amp;<br>        &quot;}&quot;,<br>        &quot;,&quot;<br>    )<br><br>RETURN<br>&quot;<br>&lt;!-- Container where the heatmap will be rendered --&gt;<br>&lt;div id=&#39;heatmap&#39; style=&#39;width:100%;height:450px;&#39;&gt;&lt;/div&gt;<br><br>&lt;script&gt;<br><br>(function(){<br><br>    // Load Plotly dynamically (only if it&#39;s not already loaded)<br>    function loadPlotly(callback){<br>        if(typeof Plotly !== &#39;undefined&#39;){<br>            callback(); // Plotly already available → run immediately<br>        } else {<br>            var script = document.createElement(&#39;script&#39;);<br>            script.src = &#39;https://cdn.plot.ly/plotly-2.27.0.min.js&#39;; //cdn<br>            script.onload = callback; // Run after loading<br>            document.head.appendChild(script);<br>        }<br>    }<br><br>    // Wait until Plotly is ready before executing the chart code<br>    loadPlotly(function(){<br><br>        // Inject DAX-generated data into JavaScript<br>        var rawData = [&quot; &amp; JsonData &amp; &quot;];<br><br>        // Convert a date into ISO week number (1–53)<br>        function getISOWeek(date) {<br>            const d = new Date(date);<br>            d.setHours(0,0,0,0);<br>            d.setDate(d.getDate() + 3 - (d.getDay() + 6) % 7);<br>            const week1 = new Date(d.getFullYear(),0,4);<br>            return 1 + Math.round(((d - week1) / 86400000<br>                   - 3 + (week1.getDay() + 6) % 7) / 7);<br>        }<br><br>        // Convert JavaScript day (Sunday=0) → Monday=1 ... Sunday=7<br>        function getDayNumber(date){<br>            let d = new Date(date);<br>            let day = d.getDay();<br>            return day === 0 ? 7 : day;<br>        }<br><br>        var weeks = 53; // Maximum number of weeks in a year<br>        var days = 7;   // Days of the week<br><br>        // Create empty 7x53 matrix (rows = days, columns = weeks)<br>        var z =<br>            Array.from({length: days},<br>                () =&gt; Array(weeks).fill(null)<br>            );<br><br>        // Fill matrix with values from dataset<br>        rawData.forEach(row =&gt; {<br>            var week = getISOWeek(row.date); // Get week index<br>            var day = getDayNumber(row.date); // Get day index<br>            z[day-1][week-1] = row.value; // Place value into correct cell<br>        });<br><br>        // Define the heatmap<br>        var trace = {<br>            type: &#39;heatmap&#39;,<br>            z: z, // Data matrix<br>            x: Array.from({length: weeks},(_,i)=&gt;i+1), // Week numbers<br>            y: [<br>                &#39;Monday&#39;,&#39;Tuesday&#39;,&#39;Wednesday&#39;,<br>                &#39;Thursday&#39;,&#39;Friday&#39;,&#39;Saturday&#39;,&#39;Sunday&#39;<br>            ],<br>            // Color scale can be changed:<br>            // &#39;Viridis&#39;, &#39;Blues&#39;, &#39;Cividis&#39;, &#39;RdYlGn&#39;, or custom palettes<br>            colorscale: &#39;Viridis&#39;,<br><br>            // Tooltip content when hovering over a cell<br>            hovertemplate:<br>                &#39;&lt;b&gt;Week %{x}&lt;/b&gt;&lt;br&gt;%{y}&lt;br&gt;Value %{z}&lt;extra&gt;&lt;/extra&gt;&#39;,<br><br>            // Color legend<br>            colorbar: { title: &#39;Activity&#39; }<br>        };<br><br>        // Layout settings<br>        var layout = {<br>            title: &#39;GitHub-Style Calendar Heatmap&#39;,<br>            xaxis: { title: &#39;Week Number&#39;, side:&#39;bottom&#39; },<br>            yaxis: { title: &#39;&#39;, autorange:&#39;reversed&#39; }, // Monday on top<br>            height: 400<br>        };<br><br>        // Render the chart inside the &#39;heatmap&#39; div<br>        Plotly.newPlot(&#39;heatmap&#39;,[trace],layout);<br><br>    });<br><br>})();<br><br>&lt;/script&gt;<br>&quot;</pre><h3>What this changed for me</h3><p>Before building this, I mostly relied on:</p><ul><li>Line charts</li><li>Tables</li><li>Standard KPIs</li></ul><p>This heatmap does.</p><p>It shows:</p><ul><li>consistency vs. randomness</li><li>strong periods vs. weak ones</li><li>habits, not just outcomes</li></ul><p>And honestly, once you start seeing your data this way, it’s hard to go back.</p><h3>⚡If you’re thinking about building one</h3><p>Think about:</p><ul><li>What “activity” means in your context</li><li>What patterns you’re trying to uncover</li><li>Whether daily granularity actually matters</li></ul><p>I think this type of visualization only becomes powerful when it answers a real question.</p><p><strong>💡 </strong><a href="https://powerbi-masterclass.short.gy/pbi-gpt?utm_source=medium&amp;utm_campaign=pbi-gpt-medium-post-end"><strong>MUST TRY — Power BI GPT — Personal Power BI Learning Coach</strong></a><strong>💡</strong></p><blockquote>Don’t forget to subscribe to</blockquote><blockquote>👉 <a href="https://powerbi-masterclass.short.gy/publication?utm_source=medium&amp;utm_medium=medium-post&amp;utm_campaign=publication-medium-post-end">Power BI Publication</a></blockquote><blockquote>👉 <a href="https://powerbi-masterclass.short.gy/newsletter-medium?utm_source=medium&amp;utm_medium=medium-post&amp;utm_campaign=newsletter-medium-medium-post-end">Power BI Newsletter</a></blockquote><blockquote>and join our Power BI community:</blockquote><p><a href="https://linktr.ee/powerbi.masterclass?utm_source=medium&amp;utm_medium=medium-post&amp;utm_campaign=linktree-medium-post-end&amp;source=post_page-----63d59d50a1eb---------------------------------------">Microsoft Power BI Masterclass | Linktree</a></p><p><strong>Power BI Masterclass Article Classification</strong></p><p><strong>Level:</strong> Intermediate</p><p><strong>Category:</strong> Data Visualization</p><p><strong>Tags:</strong> Tutorial, Data Visualization</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c602c6d98454" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft-power-bi/how-i-built-a-github-style-calendar-heatmap-in-power-bi-c602c6d98454">How I Built a Calendar Heatmap in Power BI with Plotly.js</a> was originally published in <a href="https://medium.com/microsoft-power-bi">Power BI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Clean KPI Card in Power BI With DAX and HTML]]></title>
            <link>https://medium.com/microsoft-power-bi/building-a-clean-kpi-card-in-power-bi-with-dax-and-html-dfc4a0f934ea?source=rss-db08db068da8------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfc4a0f934ea</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[power-bi]]></category>
            <category><![CDATA[power-bi-tutorials]]></category>
            <dc:creator><![CDATA[Esther]]></dc:creator>
            <pubDate>Sat, 28 Mar 2026 14:01:20 GMT</pubDate>
            <atom:updated>2026-03-30T12:21:56.737Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*2uRCXN1jl4vIY1v_o84vIQ.png" /><figcaption>KPI Card in HTML and native Power BI Visual</figcaption></figure><p>Most Power BI dashboards are perfectly functional, but they often feel a bit mechanical. You get the numbers, maybe a chart or two, but the experience rarely feels intentional or thoughtfully designed.</p><p>I wanted to experiment with something slightly different: taking a simple KPI and turning it into a small, well-structured UI component using only DAX and HTML — no custom visuals, no external tools.</p><p><strong>🎁 </strong><a href="https://powerbi-masterclass.short.gy/learning-database?utm_source=medium&amp;utm_medium=medium-post&amp;utm_campaign=database-medium-post-start"><strong>Get friend links for all of our 1500&gt; Power BI learning articles here</strong></a><strong> 🎁</strong></p><h3>What I wanted to achieve</h3><p>Instead of just showing a number, the goal was to create a KPI card that:</p><ul><li>clearly highlights the main value</li><li>provides context (growth, min, average, max)</li><li>explains what is happening in plain language</li><li>stays fully interactive with slicers and charts</li></ul><h3>Step 1 — Start with the core measures</h3><p>Before thinking about layout or styling, the most important part is having clean measures that respect filter context.</p><pre>Total Sales = SUM(Sales[Amount])</pre><pre>Previous Sales =<br>CALCULATE(<br>    [Total Sales],<br>    DATEADD(Sales[Date], -1, MONTH)<br>)</pre><pre>Growth % =<br>DIVIDE(<br>    [Total Sales] - [Previous Sales],<br>    [Previous Sales]<br>)</pre><p>These measures are intentionally simple. There is no use of ALL(), because we want the KPI to react naturally to slicers and chart selections.</p><h3>Step 2 — Add logic for presentation</h3><p>Next, we introduce a few variables that control how the KPI behaves visually.</p><pre>VAR Total = [Total Sales]<br>VAR Growth = [Growth %]</pre><pre>VAR Arrow = IF(Growth &gt;= 0, &quot;▲&quot;, &quot;▼&quot;)<br>VAR Color = IF(Growth &gt;= 0, &quot;#22c55e&quot;, &quot;#ef4444&quot;)</pre><p>At this point, we are not thinking about design yet, just about how the data should be interpreted and displayed.</p><p>We can also add a simple summary that turns numbers into a short explanation:</p><pre>VAR Summary =<br>IF(<br>    Growth &gt; 0,<br>    &quot;Sales are increasing compared to last month&quot;,<br>    &quot;Sales declined compared to last month&quot;<br>)</pre><h3>Step 3 — Build the structure in HTML</h3><p>Now we start shaping the card itself. It helps to think in sections: header, value, growth, details, and summary.</p><pre>RETURN<br>&quot;<br>&lt;div style=&#39;<br>  width:380px;<br>  padding:26px;<br>  border-radius:18px;<br>  background:#111827;<br>  color:white;<br>  font-family:sans-serif;<br>&#39;&gt;<br>&quot;</pre><p>This outer container defines the size, spacing, and overall look of the card.</p><h3>Step 4 — Show the main value</h3><p>The main number should be the most prominent element.</p><pre>&lt;div style=&#39;<br>  font-size:46px;<br>  font-weight:700;<br>  margin-bottom:8px;<br>  color:#fbbf24;<br>&#39;&gt;<br>  &quot; &amp; FORMAT(Total, &quot;$#,##0&quot;) &amp; &quot;<br>&lt;/div&gt;</pre><p>The goal here is clarity: large size, strong contrast, and simple formatting.</p><h3>Step 5 — Add growth context</h3><p>The KPI becomes much more useful when you add a comparison.</p><pre>&lt;div style=&#39;display:flex;justify-content:space-between;margin-bottom:15px;&#39;&gt;</pre><pre>  &lt;div style=&#39;<br>    color:&quot; &amp; Color &amp; &quot;;<br>    font-size:14px;<br>    font-weight:600;<br>  &#39;&gt;<br>    &quot; &amp; Arrow &amp; &quot; &quot; &amp; FORMAT(Growth,&quot;0.0%&quot;) &amp; &quot;<br>  &lt;/div&gt;</pre><pre>  &lt;div style=&#39;font-size:12px;color:#6b7280;&#39;&gt;<br>    vs last month<br>  &lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><p>This small section adds immediate meaning to the number without overwhelming the layout.</p><h3>Step 6 — Add supporting statistics</h3><p>To give more context, we include minimum, average, and maximum values.</p><pre>&lt;div style=&#39;display:flex;justify-content:space-between;margin-bottom:14px;&#39;&gt;</pre><pre>  &lt;div&gt;<br>    &lt;div style=&#39;font-size:10px;color:#6b7280;&#39;&gt;MIN&lt;/div&gt;<br>    &lt;div&gt;&quot; &amp; FORMAT([Min Sales], &quot;$#,##0&quot;) &amp; &quot;&lt;/div&gt;<br>  &lt;/div&gt;</pre><pre>  &lt;div&gt;<br>    &lt;div style=&#39;font-size:10px;color:#6b7280;&#39;&gt;AVG&lt;/div&gt;<br>    &lt;div&gt;&quot; &amp; FORMAT([Avg Sales], &quot;$#,##0&quot;) &amp; &quot;&lt;/div&gt;<br>  &lt;/div&gt;</pre><pre>  &lt;div&gt;<br>    &lt;div style=&#39;font-size:10px;color:#6b7280;&#39;&gt;MAX&lt;/div&gt;<br>    &lt;div&gt;&quot; &amp; FORMAT([Max Sales], &quot;$#,##0&quot;) &amp; &quot;&lt;/div&gt;<br>  &lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><p>These values are not the focus, but they help the user understand the range and distribution.</p><h3>Step 7 — Add a simple summary</h3><p>Finally, we include a short sentence that interprets the data.</p><pre>&lt;div style=&#39;<br>  font-size:12px;<br>  color:#9ca3af;<br>  background:#020617;<br>  padding:10px;<br>  border-radius:10px;<br>&#39;&gt;<br>  &quot; &amp; Summary &amp; &quot;<br>&lt;/div&gt;</pre><p>This is a small detail, but it makes the KPI feel more complete and easier to understand.</p><h3>Interaction with the rest of the report</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*hgBjn6INy4pRbxdEQpSWsg.gif" /></figure><p>One important detail is that this KPI is placed next to a native Power BI bar chart.</p><p>Because all measures respect filter context:</p><ul><li>the Date slicer filters both the KPI and the chart</li><li>clicking on the chart updates the KPI</li><li>selecting a range keeps everything in sync</li></ul><p>There is no extra logic required — just clean measures and a proper model.</p><h3>Final thought</h3><p>What started as a simple KPI turned into a small, reusable UI component. The main takeaway is not about HTML or styling, but about combining, clear structure, simple DAX and consistent interaction.</p><p>When those pieces come together, even a basic dashboard can feel much more thoughtful and usable.</p><p><strong>💡 </strong><a href="https://powerbi-masterclass.short.gy/pbi-gpt?utm_source=medium&amp;utm_campaign=pbi-gpt-medium-post-end"><strong>MUST TRY — Power BI GPT — Personal Power BI Learning Coach</strong></a><strong>💡</strong></p><blockquote>Don’t forget to subscribe to</blockquote><blockquote>👉 <a href="https://powerbi-masterclass.short.gy/publication?utm_source=medium&amp;utm_medium=medium-post&amp;utm_campaign=publication-medium-post-end">Power BI Publication</a></blockquote><blockquote>👉 <a href="https://powerbi-masterclass.short.gy/newsletter-medium?utm_source=medium&amp;utm_medium=medium-post&amp;utm_campaign=newsletter-medium-medium-post-end">Power BI Newsletter</a></blockquote><blockquote>and join our Power BI community:</blockquote><p><a href="https://linktr.ee/powerbi.masterclass?utm_source=medium&amp;utm_medium=medium-post&amp;utm_campaign=linktree-medium-post-end&amp;source=post_page-----63d59d50a1eb---------------------------------------">Microsoft Power BI Masterclass | Linktree</a></p><p><strong>Power BI Masterclass Article Classification</strong></p><p><strong>Level:</strong> Intermediate</p><p><strong>Category:</strong> Data Visualization</p><p><strong>Tags:</strong> Tutorial, Data Visualization</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfc4a0f934ea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft-power-bi/building-a-clean-kpi-card-in-power-bi-with-dax-and-html-dfc4a0f934ea">Building a Clean KPI Card in Power BI With DAX and HTML</a> was originally published in <a href="https://medium.com/microsoft-power-bi">Power BI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an Interactive Dam Map with Dash]]></title>
            <link>https://medium.com/@esthersm/building-an-interactive-dam-map-with-dash-9134130a1a01?source=rss-db08db068da8------2</link>
            <guid isPermaLink="false">https://medium.com/p/9134130a1a01</guid>
            <category><![CDATA[dash]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[interactive]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[plotly]]></category>
            <dc:creator><![CDATA[Esther]]></dc:creator>
            <pubDate>Tue, 24 Mar 2026 12:38:49 GMT</pubDate>
            <atom:updated>2026-04-05T12:17:10.077Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Step-by-Step Look at Filtering, Maps, clickData and Dash Bootstrap</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DgxQNNFwWHu68zOU5yEKOQ.png" /><figcaption>Image by Author in a Plotly Dash app</figcaption></figure><p>Dataset from Figure Friday, which was a great and fun Friday activity as part of the plotly community. The complete dataset can be found on the <a href="https://nid.sec.usace.army.mil/#/downloads"><strong>National Inventory of Dams website</strong></a><strong>.</strong></p><p>A detail from the dataset:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8dxSmXq1wmGmw6L-lcqLmQ.png" /></figure><p>When I first opened this dataset about US dams, I quickly realized that just looking at rows in a table was not going to give me any real understanding, because geographic data only starts to make sense when you actually see it on a map and interact with it in a way that lets you explore details on demand.</p><p>So instead of analyzing it in a notebook, I decided to build a small Dash application that would let me filter, visualize, and click through the data in a more natural way, while also forcing myself to understand how Dash callbacks actually work under the hood.</p><h3>Loading and Preparing the Data</h3><p>Before building anything visual, the first step is always to make sure the dataset is clean enough to support interaction, because even a few invalid values can break maps or callbacks in subtle ways.</p><pre>df = pd.read_csv(&quot;https://raw.githubusercontent.com/banana0000/US-Damps/refs/heads/main/nation-dams.csv&quot;)</pre><pre>df[&#39;Hazard Potential Classification&#39;] = df[&#39;Hazard Potential Classification&#39;].fillna(&#39;Unknown&#39;)</pre><pre>df[&#39;Latitude&#39;] = pd.to_numeric(df[&#39;Latitude&#39;], errors=&#39;coerce&#39;)<br>df[&#39;Longitude&#39;] = pd.to_numeric(df[&#39;Longitude&#39;], errors=&#39;coerce&#39;)<br>df[&#39;Year Completed&#39;] = pd.to_numeric(df[&#39;Year Completed&#39;], errors=&#39;coerce&#39;)</pre><p>Here I am doing three important things at once, even if it doesn’t look like much at first glance, because I am standardizing missing categorical values, converting coordinates into numeric format so Plotly can use them, and making sure that year values can be filtered later without issues.</p><h3>Building the Interactive Map</h3><p>Once the data is usable, the next step is creating the map itself, which is handled by Plotly Express and its scatter_mapbox function.</p><pre>fig_map = px.scatter_mapbox(<br>    dff_map,<br>    lat=&quot;Latitude&quot;,<br>    lon=&quot;Longitude&quot;,<br>    color=&quot;Hazard Potential Classification&quot;,<br>    hover_name=&quot;Dam Name&quot;,<br>    custom_data=[&quot;Dam Name&quot;],<br>    zoom=3,<br>    mapbox_style=&quot;carto-positron&quot;,<br>)</pre><p>There are a few key parameters here that are worth understanding in detail, because they directly affect how the app behaves.</p><p>The lat and lon fields define where each dam is placed, while color groups them by hazard classification, which makes it easier to spot patterns across the map without reading any labels.</p><p>The hover_name controls what appears when you move your mouse over a point, but more importantly, custom_data stores hidden information that will later be used when handling click events.</p><p>Without custom_data, the app would not know which exact dam was clicked, which means the interaction layer would be disconnected from the dataset.</p><h3>Adding Filters with Dash</h3><p>To make the dashboard useful, I added dropdown filters that allow users to narrow down the dataset based on state, hazard level, and year.</p><p>Inside the callback, the filtering logic looks like this:</p><pre>dff = df.copy()</pre><pre>if selected_states:<br>    dff = dff[dff[&#39;State&#39;].isin(selected_states)]</pre><pre>if selected_hazards:<br>    dff = dff[dff[&#39;Hazard Potential Classification&#39;].isin(selected_hazards)]</pre><pre>if selected_years:<br>    dff = dff[dff[&#39;Year Completed&#39;].isin(selected_years)]</pre><p>This pattern is simple but powerful, because it creates a pipeline where each filter progressively reduces the dataset, and the result is then used everywhere else in the app.</p><p>This is important because it keeps the map, KPIs, and details panel fully consistent with each other.</p><h3>Understanding Dash Callbacks</h3><p>Dash applications are built around callbacks, which connect inputs and outputs in a reactive way.</p><p>In this case, the main callback updates multiple outputs at once:</p><pre>@app.callback(<br>    Output(&quot;map&quot;, &quot;figure&quot;),<br>    Output(&quot;kpi-count&quot;, &quot;children&quot;),<br>    Output(&quot;kpi-height&quot;, &quot;children&quot;),<br>    Output(&quot;kpi-hazard&quot;, &quot;children&quot;),<br>    Input(&quot;state-dropdown&quot;, &quot;value&quot;),<br>    Input(&quot;hazard-dropdown&quot;, &quot;value&quot;),<br>    Input(&quot;year-dropdown&quot;, &quot;value&quot;),<br>)</pre><p>Every time a user changes a filter, this function runs again, which means the dataset is re-filtered, the map is redrawn, and the KPIs are recalculated.</p><p>This is what makes the app feel dynamic without writing any frontend JavaScript.</p><h3>Handling Click Events with clickData</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*28suyK000knOhKYLRi4Z2g.gif" /><figcaption>The result of the click data is inside a dash bootstrap card</figcaption></figure><p>The most interesting part of the app is what happens when a user clicks on a point on the map, because this is where visualization turns into interaction.</p><p>Dash provides access to click events through the clickData property, which contains information about the selected point.</p><pre>@app.callback(<br>    Output(&quot;details-card-body&quot;, &quot;children&quot;),<br>    Input(&quot;map&quot;, &quot;clickData&quot;),<br>)<br>def show_dam_details(clickData):<br>    if clickData and &quot;points&quot; in clickData:<br>        dam_name = clickData[&quot;points&quot;][0][&quot;customdata&quot;][0]</pre><p>This line extracts the dam name from the clicked point, using the custom_data we defined earlier in the map.</p><p>Once we have the name, we can retrieve the full record:</p><pre>dam = dff[dff[&quot;Dam Name&quot;] == dam_name].iloc[0]</pre><p>And then display all relevant information in a structured way.</p><p>This creates a direct link between user interaction and data retrieval, which is the core idea behind interactive dashboards.</p><h3>Why clickData Changes Everything</h3><p>Without clickData, the map would only allow passive exploration through hovering and filtering, but with it, the user can actively select specific elements and get detailed information instantly.</p><p>This transforms the dashboard from a static visualization into something that behaves more like an application, where every action produces a meaningful response.</p><p>Full code with HTMLand CSS:</p><pre>import pandas as pd<br>import dash<br>from dash import dcc, html, Input, Output, State<br>import dash_bootstrap_components as dbc<br>import plotly.express as px<br><br># Load and preprocess data<br>df = pd.read_csv(<br>    &quot;https://raw.githubusercontent.com/banana0000/US-Damps/refs/heads/main/nation-dams.csv&quot;<br>)<br>df[&#39;Hazard Potential Classification&#39;] = df[&#39;Hazard Potential Classification&#39;].fillna(&#39;Unknown&#39;)<br>df[&#39;Latitude&#39;] = pd.to_numeric(df[&#39;Latitude&#39;], errors=&#39;coerce&#39;)<br>df[&#39;Longitude&#39;] = pd.to_numeric(df[&#39;Longitude&#39;], errors=&#39;coerce&#39;)<br>df[&#39;Year Completed&#39;] = pd.to_numeric(df[&#39;Year Completed&#39;], errors=&#39;coerce&#39;)<br><br>def get_state_options(dff):<br>    return [<br>        {&quot;label&quot;: s, &quot;value&quot;: s}<br>        for s in sorted(dff[&#39;State&#39;].dropna().unique())<br>    ]<br><br>def get_hazard_options(dff):<br>    return [<br>        {&quot;label&quot;: h, &quot;value&quot;: h}<br>        for h in sorted(dff[&#39;Hazard Potential Classification&#39;].dropna().unique())<br>    ]<br><br>def get_year_options(dff):<br>    return [<br>        {&quot;label&quot;: str(int(y)), &quot;value&quot;: int(y)}<br>        for y in sorted(dff[&#39;Year Completed&#39;].dropna().unique())<br>    ]<br><br>kpi_color = &quot;#1F2020&quot;<br>my_colors = [<br>    &quot;#2E8DAA&quot;, &quot;#0C2C57&quot;,<br>    &quot;#22E03B&quot;, &quot;#E9E909&quot;<br>]<br><br>gradient_bg = {<br>    &quot;background&quot;: &quot;linear-gradient(90deg,white,lightblue)&quot;,<br>    &quot;minHeight&quot;: &quot;100vh&quot;,<br>    &quot;width&quot;: &quot;100vw&quot;,<br>    &quot;paddingBottom&quot;: &quot;32px&quot;<br>}<br><br>card_style = {<br>    &quot;backgroundColor&quot;: &quot;white&quot;,<br>    &quot;borderRadius&quot;: &quot;16px&quot;,<br>    &quot;boxShadow&quot;: &quot;0 4px 24px rgba(0,0,0,0.08)&quot;,<br>    &quot;padding&quot;: &quot;0&quot;,<br>}<br><br># KPI card style for compact, side-by-side display<br>kpi_card_style = {<br>    &quot;backgroundColor&quot;: &quot;white&quot;,<br>    &quot;borderRadius&quot;: &quot;12px&quot;,<br>    &quot;boxShadow&quot;: &quot;0 2px 8px rgba(0,0,0,0.06)&quot;,<br>    &quot;padding&quot;: &quot;0.75rem 1rem&quot;,<br>    &quot;minWidth&quot;: &quot;250px&quot;,<br>    &quot;maxWidth&quot;: &quot;180px&quot;,<br>    &quot;margin&quot;: &quot;0 8px&quot;,<br>    &quot;display&quot;: &quot;inline-block&quot;,<br>    &quot;verticalAlign&quot;: &quot;top&quot;,<br>}<br><br>app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])<br><br>app.layout = html.Div(<br>    [<br>        dbc.Container(<br>            [<br>                html.H1(<br>                    &quot;USA Dams Dashboard&quot;,<br>                    className=&quot;my-4 text-left text-dark&quot;,<br>                    style={&quot;fontWeight&quot;: &quot;bold&quot;, &quot;letterSpacing&quot;: &quot;1px&quot;, &quot;font-family&quot;:&quot;Viridis&quot;},<br>                ),<br>                dbc.Row(<br>                    [<br>                        # Sidebar filters (left)<br>                        dbc.Col(<br>                            [<br>                                dbc.Card(<br>                                    [<br>                                        dbc.CardHeader(<br>                                            &quot;Filters&quot;,<br>                                            className=&quot;bg-secondary text-white border-0&quot;,<br>                                            style={<br>                                                &quot;padding&quot;: &quot;1rem 1.25rem&quot;,<br>                                                &quot;borderRadius&quot;: &quot;16px 16px 0 0&quot;,<br>                                                &quot;fontWeight&quot;: &quot;bold&quot;,<br>                                                &quot;fontSize&quot;: &quot;1.1rem&quot;,<br>                                            },<br>                                        ),<br>                                        dbc.CardBody(<br>                                            [<br>                                                html.Label(&quot;State&quot;, className=&quot;text-primary mb-1&quot;),<br>                                                dcc.Dropdown(<br>                                                    id=&quot;state-dropdown&quot;,<br>                                                    options=get_state_options(df),<br>                                                    multi=True,<br>                                                    placeholder=&quot;Select state(s)&quot;,<br>                                                    style={&quot;margin-bottom&quot;: &quot;18px&quot;},<br>                                                ),<br>                                                html.Label(<br>                                                    &quot;Hazard Potential&quot;, className=&quot;text-primary mb-1&quot;<br>                                                ),<br>                                                dcc.Dropdown(<br>                                                    id=&quot;hazard-dropdown&quot;,<br>                                                    options=get_hazard_options(df),<br>                                                    multi=True,<br>                                                    placeholder=&quot;Select hazard potential(s)&quot;,<br>                                                    style={&quot;margin-bottom&quot;: &quot;18px&quot;},<br>                                                ),<br>                                                html.Label(<br>                                                    &quot;Year Completed&quot;, className=&quot;text-primary mb-1&quot;<br>                                                ),<br>                                                dcc.Dropdown(<br>                                                    id=&quot;year-dropdown&quot;,<br>                                                    options=get_year_options(df),<br>                                                    multi=True,<br>                                                    placeholder=&quot;Select year(s)&quot;,<br>                                                    style={&quot;margin-bottom&quot;: &quot;6px&quot;},<br>                                                ),<br>                                            ],<br>                                            style={&quot;padding&quot;: &quot;1.25rem&quot;},<br>                                        ),<br>                                    ],<br>                                    className=&quot;shadow border-0 mb-4&quot;,<br>                                    style={<br>                                        **card_style,<br>                                        &quot;marginTop&quot;: &quot;120px&quot;,<br>                                        &quot;marginLeft&quot;: &quot;78px&quot;,<br>                                        &quot;minWidth&quot;: &quot;260px&quot;,<br>                                        &quot;maxWidth&quot;: &quot;400px&quot;,<br>                                    },<br>                                ),<br>                            ],<br>                            xs=12, sm=12, md=4, lg=3,<br>                            style={&quot;paddingRight&quot;: &quot;0&quot;},<br>                        ),<br>                        # Main content (KPIs + map)<br>                        dbc.Col(<br>                            [<br>                                # KPI cards in a single row, always side by side<br>                                html.Div(<br>                                    [<br>                                        dbc.Card(<br>                                            dbc.CardBody(<br>                                                [<br>                                                    html.H6(<br>                                                        &quot;Total Dams&quot;,<br>                                                        style={<br>                                                            &quot;fontWeight&quot;: &quot;bold&quot;,<br>                                                            &quot;color&quot;: kpi_color,<br>                                                            &quot;fontSize&quot;: &quot;1rem&quot;,<br>                                                            &quot;marginBottom&quot;: &quot;0.3rem&quot;,<br>                                                        },<br>                                                    ),<br>                                                    html.H4(<br>                                                        id=&quot;kpi-count&quot;,<br>                                                        style={<br>                                                            &quot;fontWeight&quot;: &quot;normal&quot;,<br>                                                            &quot;color&quot;: kpi_color,<br>                                                            &quot;marginBottom&quot;: &quot;0&quot;,<br>                                                        },<br>                                                    ),<br>                                                ]<br>                                            ),<br>                                            className=&quot;shadow border-0&quot;,<br>                                            style=kpi_card_style,<br>                                        ),<br>                                        dbc.Card(<br>                                            dbc.CardBody(<br>                                                [<br>                                                    html.H6(<br>                                                        &quot;Average Height (ft)&quot;,<br>                                                        style={<br>                                                            &quot;fontWeight&quot;: &quot;bold&quot;,<br>                                                            &quot;color&quot;: kpi_color,<br>                                                            &quot;fontSize&quot;: &quot;1rem&quot;,<br>                                                            &quot;marginBottom&quot;: &quot;0.3rem&quot;,<br>                                                        },<br>                                                    ),<br>                                                    html.H4(<br>                                                        id=&quot;kpi-height&quot;,<br>                                                        style={<br>                                                            &quot;fontWeight&quot;: &quot;normal&quot;,<br>                                                            &quot;color&quot;: kpi_color,<br>                                                            &quot;marginBottom&quot;: &quot;0&quot;,<br>                                                        },<br>                                                    ),<br>                                                ]<br>                                            ),<br>                                            className=&quot;shadow border-0&quot;,<br>                                            style=kpi_card_style,<br>                                        ),<br>                                        dbc.Card(<br>                                            dbc.CardBody(<br>                                                [<br>                                                    html.H6(<br>                                                        &quot;Most Common Hazard&quot;,<br>                                                        style={<br>                                                            &quot;fontWeight&quot;: &quot;bold&quot;,<br>                                                            &quot;color&quot;: kpi_color,<br>                                                            &quot;fontSize&quot;: &quot;1rem&quot;,<br>                                                            &quot;marginBottom&quot;: &quot;0.3rem&quot;,<br>                                                        },<br>                                                    ),<br>                                                    html.H4(<br>                                                        id=&quot;kpi-hazard&quot;,<br>                                                        style={<br>                                                            &quot;fontWeight&quot;: &quot;normal&quot;,<br>                                                            &quot;color&quot;: kpi_color,<br>                                                            &quot;marginBottom&quot;: &quot;0&quot;,<br>                                                        },<br>                                                    ),<br>                                                ]<br>                                            ),<br>                                            className=&quot;shadow border-0&quot;,<br>                                            style=kpi_card_style,<br>                                        ),<br>                                    ],<br>                                    style={<br>                                        &quot;display&quot;: &quot;flex&quot;,<br>                                        &quot;justifyContent&quot;: &quot;center&quot;,<br>                                        &quot;alignItems&quot;: &quot;center&quot;,<br>                                        &quot;marginBottom&quot;: &quot;18px&quot;,<br>                                    },<br>                                ),<br>                                # Map card<br>                                dbc.Card(<br>                                    [<br>                                        dbc.CardHeader(<br>                                            &quot;Dams Map&quot;,<br>                                            className=&quot;bg-secondary text-white border-0&quot;,<br>                                            style={<br>                                                &quot;padding&quot;: &quot;1rem 1.25rem&quot;,<br>                                                &quot;borderRadius&quot;: &quot;16px 16px 0 0&quot;,<br>                                                &quot;fontWeight&quot;: &quot;bold&quot;,<br>                                            },<br>                                        ),<br>                                        dbc.CardBody(<br>                                            [<br>                                                dcc.Graph(<br>                                                    id=&quot;map&quot;,<br>                                                    style={&quot;height&quot;: &quot;500px&quot;},<br>                                                    config={<br>                                                        &quot;scrollZoom&quot;: True,<br>                                                        &quot;displayModeBar&quot;: True,<br>                                                    }<br>                                                ),<br>                                            ],<br>                                            style={&quot;padding&quot;: &quot;1.25rem&quot;},<br>                                        ),<br>                                    ],<br>                                    className=&quot;mb-4 shadow border-0&quot;,<br>                                    style={**card_style},<br>                                ),<br>                                dcc.Location(id=&quot;dummy-location&quot;, refresh=True),<br>                            ],<br>                            xs=12, sm=12, md=8, lg=6,<br>                        ),<br>                        # Dam details (right) - always visible<br>                        dbc.Col(<br>                            dbc.Card(<br>                                [<br>                                    dbc.CardHeader(<br>                                        &quot;Click on a point to see dam details&quot;,<br>                                        className=&quot;bg-secondary text-white border-0&quot;,<br>                                        style={<br>                                            &quot;padding&quot;: &quot;1rem 1.25rem&quot;,<br>                                            &quot;borderRadius&quot;: &quot;16px 16px 0 0&quot;,<br>                                            &quot;fontWeight&quot;: &quot;bold&quot;,<br>                                        },<br>                                        id=&quot;details-card-title&quot;,<br>                                    ),<br>                                    dbc.CardBody(<br>                                        html.Div(id=&quot;details-card-body&quot;),<br>                                        style={&quot;padding&quot;: &quot;1.25rem&quot;},<br>                                    ),<br>                                ],<br>                                className=&quot;h-80 mt-4 shadow border-0&quot;,<br>                                style={**card_style, &quot;minWidth&quot;: &quot;260px&quot;, &quot;maxWidth&quot;: &quot;400px&quot;},<br>                            ),<br>                            xs=12, sm=12, md=12, lg=3,<br>                            style={&quot;marginTop&quot;: &quot;120px&quot;},<br>                        ),<br>                    ],<br>                    className=&quot;g-4&quot;,  # smaller gutter for closer columns<br>                ),<br>            ],<br>            fluid=True,<br>            style={<br>                &quot;background&quot;: &quot;transparent&quot;,<br>                &quot;minHeight&quot;: &quot;100vh&quot;,<br>                &quot;fontFamily&quot;: &quot;Segoe UI, Arial, sans-serif&quot;,<br>            },<br>        )<br>    ],<br>    style=gradient_bg,<br>)<br><br># --- Dynamic filter options callback ---<br>@app.callback(<br>    Output(&quot;state-dropdown&quot;, &quot;options&quot;),<br>    Output(&quot;hazard-dropdown&quot;, &quot;options&quot;),<br>    Output(&quot;year-dropdown&quot;, &quot;options&quot;),<br>    Input(&quot;state-dropdown&quot;, &quot;value&quot;),<br>    Input(&quot;hazard-dropdown&quot;, &quot;value&quot;),<br>    Input(&quot;year-dropdown&quot;, &quot;value&quot;),<br>)<br>def update_filter_options(selected_states, selected_hazards, selected_years):<br>    # Filter dropdown options based on current selections<br>    dff = df.copy()<br>    if selected_states:<br>        dff = dff[dff[&#39;State&#39;].isin(selected_states)]<br>    if selected_hazards:<br>        dff = dff[dff[&#39;Hazard Potential Classification&#39;].isin(selected_hazards)]<br>    if selected_years:<br>        dff = dff[dff[&#39;Year Completed&#39;].isin(selected_years)]<br><br>    state_options = get_state_options(df if not (selected_hazards or selected_years) else dff)<br>    hazard_options = get_hazard_options(df if not (selected_states or selected_years) else dff)<br>    year_options = get_year_options(df if not (selected_states or selected_hazards) else dff)<br>    return state_options, hazard_options, year_options<br><br># --- Main dashboard callback: map and KPIs ---<br>@app.callback(<br>    Output(&quot;map&quot;, &quot;figure&quot;),<br>    Output(&quot;kpi-count&quot;, &quot;children&quot;),<br>    Output(&quot;kpi-height&quot;, &quot;children&quot;),<br>    Output(&quot;kpi-hazard&quot;, &quot;children&quot;),<br>    Input(&quot;state-dropdown&quot;, &quot;value&quot;),<br>    Input(&quot;hazard-dropdown&quot;, &quot;value&quot;),<br>    Input(&quot;year-dropdown&quot;, &quot;value&quot;),<br>)<br>def update_dashboard(selected_states, selected_hazards, selected_years):<br>    # Filter data based on dropdowns<br>    dff = df.copy()<br>    if selected_states:<br>        dff = dff[dff[&#39;State&#39;].isin(selected_states)]<br>    if selected_hazards:<br>        dff = dff[dff[&#39;Hazard Potential Classification&#39;].isin(selected_hazards)]<br>    if selected_years:<br>        dff = dff[dff[&#39;Year Completed&#39;].isin(selected_years)]<br>    dff_map = dff.dropna(subset=[&quot;Latitude&quot;, &quot;Longitude&quot;])<br><br>    # Create the map figure<br>    if dff_map.empty:<br>        fig_map = px.scatter_mapbox(<br>            pd.DataFrame({&quot;Latitude&quot;: [], &quot;Longitude&quot;: []}),<br>            lat=&quot;Latitude&quot;,<br>            lon=&quot;Longitude&quot;,<br>            zoom=2,<br>            height=500,<br>            mapbox_style=&quot;carto-positron&quot;<br>        )<br>    else:<br>        fig_map = px.scatter_mapbox(<br>            dff_map,<br>            lat=&quot;Latitude&quot;,<br>            lon=&quot;Longitude&quot;,<br>            color=&quot;Hazard Potential Classification&quot;,<br>            color_discrete_sequence=my_colors,<br>            hover_name=&quot;Dam Name&quot;,   # Only show dam name in tooltip<br>            hover_data=[],           # No extra data in tooltip<br>            custom_data=[&quot;Dam Name&quot;],<br>            zoom=3,<br>            height=500,<br>            mapbox_style=&quot;carto-positron&quot;,<br>        )<br>        fig_map.update_traces(<br>            marker=dict(size=12, opacity=0.92),<br>            hovertemplate=&quot;%{hovertext}&lt;extra&gt;&lt;/extra&gt;&quot;,  # Only dam name in tooltip<br>        )<br>    fig_map.update_layout(<br>        margin={&quot;r&quot;: 0, &quot;t&quot;: 0, &quot;l&quot;: 0, &quot;b&quot;: 0},<br>        paper_bgcolor=&quot;rgba(0,0,0,0)&quot;,<br>        plot_bgcolor=&quot;rgba(0,0,0,0)&quot;,<br>        font_color=&quot;#222831&quot;,<br>        legend=dict(<br>            bgcolor=&quot;rgba(255,255,255,0.8)&quot;,<br>            font=dict(color=&quot;#222831&quot;),<br>            orientation=&quot;h&quot;,<br>            yanchor=&quot;bottom&quot;,<br>            y=1.02,<br>            xanchor=&quot;center&quot;,<br>            x=0.5,<br>        ),<br>        dragmode=&quot;zoom&quot;,  # Default to zoom mode<br>    )<br><br>    # KPIs<br>    kpi_count = f&quot;{len(dff):,}&quot;<br>    kpi_height = (<br>        f&quot;{dff[&#39;Dam Height (Ft)&#39;].mean():.1f}&quot; if not dff.empty else &quot;n.a.&quot;<br>    )<br>    kpi_hazard = (<br>        dff[&#39;Hazard Potential Classification&#39;].mode()[0] if not dff.empty else &quot;n.a.&quot;<br>    )<br><br>    return (<br>        fig_map,<br>        kpi_count,<br>        kpi_height,<br>        kpi_hazard,<br>    )<br><br># --- Dam details card callback ---<br>@app.callback(<br>    Output(&quot;details-card-title&quot;, &quot;children&quot;),<br>    Output(&quot;details-card-body&quot;, &quot;children&quot;),<br>    Input(&quot;map&quot;, &quot;clickData&quot;),<br>    State(&quot;state-dropdown&quot;, &quot;value&quot;),<br>    State(&quot;hazard-dropdown&quot;, &quot;value&quot;),<br>    State(&quot;year-dropdown&quot;, &quot;value&quot;),<br>)<br>def show_dam_details(clickData, selected_states, selected_hazards, selected_years):<br>    if clickData and &quot;points&quot; in clickData:<br>        dam_name = clickData[&quot;points&quot;][0][&quot;customdata&quot;][0]<br>        dff = df.copy()<br>        if selected_states:<br>            dff = dff[dff[&#39;State&#39;].isin(selected_states)]<br>        if selected_hazards:<br>            dff = dff[dff[&#39;Hazard Potential Classification&#39;].isin(selected_hazards)]<br>        if selected_years:<br>            dff = dff[dff[&#39;Year Completed&#39;].isin(selected_years)]<br>        dam = dff[dff[&quot;Dam Name&quot;] == dam_name]<br>        if not dam.empty:<br>            dam = dam.iloc[0]<br>            title = &quot;Dam Details&quot;<br>            body = [<br>                html.H4(dam[&quot;Dam Name&quot;], className=&quot;text-primary&quot;),<br>                html.Hr(),<br>                html.P(f&quot;State: {dam[&#39;State&#39;]}&quot;),<br>                html.P(f&quot;County: {dam[&#39;County&#39;]}&quot;),<br>                html.P(f&quot;City: {dam[&#39;City&#39;]}&quot;),<br>                html.P(<br>                    f&quot;Year Completed: {int(dam[&#39;Year Completed&#39;]) if pd.notnull(dam[&#39;Year Completed&#39;]) else &#39;n.a.&#39;}&quot;<br>                ),<br>                html.P(f&quot;Dam Height (Ft): {dam[&#39;Dam Height (Ft)&#39;]}&quot;),<br>                html.P(<br>                    f&quot;Hazard Potential: {dam[&#39;Hazard Potential Classification&#39;]}&quot;<br>                ),<br>                html.P(&quot;Website: &quot;),<br>                html.A(<br>                    dam[&#39;Website URL&#39;],<br>                    href=dam[&#39;Website URL&#39;],<br>                    target=&quot;_blank&quot;,<br>                    className=&quot;text-info&quot;,<br>                )<br>                if pd.notnull(dam[&#39;Website URL&#39;])<br>                else html.Span(&quot;n.a.&quot;),<br>            ]<br>            return title, body<br>    # Default message if nothing is selected<br>    return &quot;Click on a point to see dam details&quot;, html.P(&quot;No dam selected.&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br>    app.run(debug=True)</pre><h3>Final Thoughts</h3><p>What started as a simple dataset turned into a small but fully interactive system, where data cleaning, filtering, visualization, and user interaction all work together in a single pipeline.</p><p>The most important takeaway for me was not the map itself, but how relatively small pieces like custom_data and clickData can unlock much richer interactions, without adding much complexity to the code.</p><p>And once you understand this pattern, you can apply it to almost any dataset where exploration matters more than just presentation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9134130a1a01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Building an Interactive Dash Dashboard in plotly dash]]></title>
            <link>https://medium.com/@esthersm/building-an-interactive-dash-dashboard-full-walkthrough-86ebb159cf09?source=rss-db08db068da8------2</link>
            <guid isPermaLink="false">https://medium.com/p/86ebb159cf09</guid>
            <category><![CDATA[plotly]]></category>
            <category><![CDATA[dash]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[interactive]]></category>
            <dc:creator><![CDATA[Esther]]></dc:creator>
            <pubDate>Sun, 22 Mar 2026 14:28:21 GMT</pubDate>
            <atom:updated>2026-04-05T11:51:25.968Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Building an Interactive Dash Dashboard in plotly dash</strong></h3><h4>I Spent a Weekend Building a Dash App — This Is What I Learned</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7IfIyRdIRFLgDY1O5c36Lg.png" /></figure><p>Why I Spent My Weekend Building a Raleigh Permit Tracker (And What It Taught Me About Dash)</p><p>We’ve all seen them: data dashboards that look stunning at first glance but feel completely hollow once you actually try to use them. When I stumbled upon the dataset for building permits in Raleigh, NC, I didn’t want to create just another static map. I wanted to build a tool that answers a real-world question: <em>“Where is the big money actually moving in a city?”</em></p><p>To do this, I turned to the Dash + Plotly stack. Here’s a look at the logic, the frustrations, and the small UX wins I found along the way.<br><br>First, we import the libraries:</p><pre>from dash import Dash, dcc, html, Input, Output<br>import dash_bootstrap_components as dbc<br>import plotly.express as px<br>import pandas as pd<br>import numpy as np</pre><h4>Cleaning the Noise</h4><p>Before I could even think about a UI, I had to deal with the raw CSV. If there’s one thing I’ve learned, it’s that you can’t trust raw data. I found that if the fee or estprojectcost columns were missing, the map markers would either break or look completely inconsistent.</p><pre>df = pd.read_csv(&quot;https://raw.githubusercontent.com/.../Building_Permits_Issued_Past_180_Days.csv&quot;)<br>df = df.dropna(subset=[&quot;fee&quot;, &quot;estprojectcost&quot;])</pre><p>Instead of trying to patch these holes with “fake” averages, I decided to be ruthless: if the data was incomplete, I dropped it early. It’s better to have a slightly smaller, accurate dataset than a large, buggy one.</p><h4>Thinking Like a Human, Not a Computer</h4><p>A technical detail I’m particularly happy with is how I handled project costs. No user wants to filter a map by “projects costing exactly $137,842.” We don’t think like that. We think in buckets — like “mid-range” or “massive developments.”</p><p>I used pd.cut to bin the costs into human-friendly labels like &quot;10k - 50k&quot; or &quot;1M+&quot;. It’s a small UX decision, but it makes the sidebar feel intuitive rather than overwhelming.</p><pre>bins = [0, 10000, 50000, 200000, 1000000, np.inf]<br>labels = [&quot;0 - 10k&quot;, &quot;10k - 50k&quot;, &quot;50k - 200k&quot;, &quot;200k - 1M&quot;, &quot;1M+&quot;]<br><br>df[&quot;estprojectcost_bin&quot;] = pd.cut(<br>    df[&quot;estprojectcost&quot;],<br>    bins=bins,<br>    labels=labels,<br>    include_lowest=True<br>)</pre><h4>The “Single Source of Truth” Strategy</h4><p>When it came to the <strong>callbacks</strong> (the brain of the app), I avoided a common mistake I used to make: creating multiple, disconnected functions. Instead, I consolidated the logic into one central callback.</p><p>Why? Because it prevents “sync hell.” There’s nothing more annoying for a user than filtering for a specific neighborhood and seeing the map update while the KPI cards still show the totals for the entire city. One callback ensures that every part of the dashboard — the map, the total fees, and the permit count — stays perfectly in sync.</p><pre>@app.callback(<br>    Output(&quot;map-chart&quot;, &quot;figure&quot;),<br>    Input(&quot;extra-filter-0&quot;, &quot;value&quot;),<br>    Input(&quot;extra-filter-1&quot;, &quot;value&quot;),<br>)</pre><h4>Design Decisions: Dark Mode &amp; Dynamic Focus</h4><p>I chose a dark theme (carto-darkmatter) intentionally. Beyond just looking &quot;sleek,&quot; it provides a much higher contrast for geographical data points. It feels like a professional data product rather than a generic Excel export.</p><p>One thing I hate is repeating UI code. If I have five dropdowns, I don’t want to write five identical blocks of code. To solve this, I built a small helper function for my <strong>dynamic dropdowns</strong>:</p><pre>def get_options(col):<br>    return [{&quot;label&quot;: &quot;All&quot;, &quot;value&quot;: &quot;all&quot;}] + [<br>        {&quot;label&quot;: str(val), &quot;value&quot;: val}<br>        for val in sorted(df[col].dropna().unique())<br>    ]</pre><p>This “scalability mindset” meant that adding a new filter (like <em>Permit Type</em> or <em>Work Class</em>) took me exactly 5 seconds instead of 5 minutes of copy-pasting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*HCqEoXJSTbnxQw_csecSQw.gif" /></figure><h4>The Sidebar: Why Fixed Position Matters</h4><p>Most dashboards fail because the filters disappear when you scroll down to see the data. I decided to fix the sidebar to the left. It stays there, solid and reliable, while the map and KPIs scroll on the right.</p><pre>SIDEBAR_STYLE = {<br>    &quot;position&quot;: &quot;fixed&quot;,<br>    &quot;top&quot;: 0, &quot;left&quot;: 0, &quot;bottom&quot;: 0,<br>    &quot;width&quot;: &quot;270px&quot;,<br>    &quot;background&quot;: &quot;#23272b&quot;,<br>    &quot;color&quot;: &quot;#fff&quot;,<br>}</pre><p>It’s a simple CSS decision, but it makes the app feel like a <strong>pro software</strong> rather than a weekend project.</p><h4>Visualizing the Story: The Map</h4><p>The core of the dashboard is the map. I used px.scatter_mapbox because it allows for multi-dimensional storytelling. In one single visual, the user can see:</p><ol><li><strong>Where</strong> the project is (Lat/Lon)</li><li><strong>How much</strong> it costs (Marker Size)</li><li><strong>How urgent</strong> it is (Color intensity)</li></ol><pre>fig = px.scatter_mapbox(<br>    filtered,<br>    lat=&quot;latitude_perm&quot;,<br>    lon=&quot;longitude_perm&quot;,<br>    size=&quot;fee&quot;,<br>    color=&quot;fee&quot;,<br>    mapbox_style=&quot;carto-darkmatter&quot;,<br>)</pre><h4>Handling the “Empty State”</h4><p>Finally, I added something most beginners forget: <strong>Error handling for filters.</strong> If a user selects a combination of filters that returns zero results, the app shouldn’t crash or show a blank screen. I added a simple check:</p><pre>if filtered.empty:<br>    fig = empty_figure() # Shows a &quot;No data found&quot; message</pre><h4>Final Thoughts</h4><p>At the end of the day, building this taught me that the best dashboards aren’t about the most complex code. They are about how fast a human can look at a screen and understand a story.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86ebb159cf09" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>