Updated 2021-07-01 to use Dash 1.19 and fontawesome icons
Dash Bootstrap Components has a fantastic library of plug and play components that make it easy to get started.
Plotly’s documentation is focused on making tables, charts, and graphs, but for executives I find myself relying on KPI cards like this:
You can find better styled examples of these all over the place if you google ‘HTML/CSS dashboard examples.’
The magic of using Dash is that you can style these to your heart’s content with CSS and all of the values can be generated with Python, and the whole thing can be reproducible and components can be shared across projects. And the flexbox system is just fine rather than fiddling with positioning in PowerBI.
Here’s the sketch of the starter KPI dashboard:
Python Code for your app.py
file:
import dash # (version 1.19.0) pip install dash
import dash_bootstrap_components as dbc
import dash_html_components as html
= "https://use.fontawesome.com/releases/v5.8.1/css/all.css"
fontawesome_stylesheet
= dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP, fontawesome_stylesheet])
app
= html.Div([
header "H1 Text"))),
dbc.Row(dbc.Col(html.H1(
])
= dbc.Card([
card
dbc.CardBody(["Card title", className="card-title"),
html.H4(
html.P("$10.5 M",
="card-value",
className
),
html.P("Target: $10.0 M",
="card-target",
className
),
html.Span([="fas fa-arrow-circle-up up"),
html.I(className" 5.5% vs Last Year",
html.Span(="up")
className
])
])
])
= html.Div([
row
dbc.CardDeck([
card,
card,
card,
]),={'padding': '25px'}
], style
)
= html.Div([
app.layout
header,
row,
row
])
if __name__ == "__main__":
="0.0.0.0", port=8080, debug=True) app.run_server(host
The ‘up’ arrow icon is courtesy of fontawesome, which we load with the external stylesheet. Since this is all in python it’s simple to turn this into a function and create conditional (i.e. if
) statements to change the icon and color scheme for your data.
Here is the basic CSS styling that goes with this:
.card {
text-align: center;
}.card .card-title {
text-align: left;
font-weight: lighter;
}
.card .card-value {
font-size: 2rem;
}
.card .card-target {
font-size: 1rem;
font-weight: lighter;
}
.card .down {
color: red;
}
.card .up {
color: green;
}