Spaces:
Running
Running
File size: 7,562 Bytes
7002c2f 64170d0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
"""Example to show dashboard configuration."""
import pandas as pd
import vizro.models as vm
from utils._charts import COLUMN_DEFS, KPI, bar, choropleth, line, pie
from utils._helper import clean_data_and_add_columns
from vizro import Vizro
from vizro.actions import filter_interaction
from vizro.tables import dash_ag_grid
# DATA --------------------------------------------------------------------------------------------
df_complaints = pd.read_csv("https://query.data.world/s/glbdstahsuw3hjgunz3zssggk7dsfu?dws=00000")
df_complaints = clean_data_and_add_columns(df_complaints)
vm.Container.add_type("components", KPI)
# SUB-SECTIONS ------------------------------------------------------------------------------------
kpi_banner = vm.Container(
id="kpi-banner",
title="",
components=[
# Note: For some KPIs the icon/sign go in opposite directions as an increase e.g. in complaints is negative
KPI(
title="Total Complaints",
value="75.513",
icon="arrow_circle_up",
sign="delta-neg",
ref_value="6.8% vs. LY",
),
KPI(
title="Closed Complaints",
value="99.6%",
icon="arrow_circle_up",
sign="delta-pos",
ref_value="+0.2% vs. LY",
),
KPI(
title="Open Complaints",
value="0.4%",
icon="arrow_circle_down",
sign="delta-pos",
ref_value="-0.2% vs. LY",
),
KPI(
title="Timely Response",
value="98.1%",
icon="arrow_circle_up",
sign="delta-pos",
ref_value="+10.5% vs. LY",
),
KPI(
title="Closed w/o cost",
value="84.5%",
icon="arrow_circle_down",
sign="delta-neg",
ref_value="-8.5% vs. LY",
),
KPI(
title="Consumer disputed",
value="9.5%",
icon="arrow_circle_up",
sign="delta-neg",
ref_value="+2.3% vs. LY",
),
],
)
bar_charts_tabbed = vm.Tabs(
tabs=[
vm.Container(
title="By Issue",
components=[
vm.Graph(
figure=bar(
data_frame=df_complaints,
y="Issue",
x="Complaint ID",
),
)
],
),
vm.Container(
title="By Product",
components=[
vm.Graph(
figure=bar(
data_frame=df_complaints,
y="Product",
x="Complaint ID",
),
)
],
),
vm.Container(
title="By Channel",
components=[
vm.Graph(
figure=bar(
data_frame=df_complaints,
y="Channel",
x="Complaint ID",
),
)
],
),
vm.Container(
title="By Region",
components=[
vm.Graph(
figure=bar(
data_frame=df_complaints,
y="Region",
x="Complaint ID",
),
)
],
),
],
)
# PAGES --------------------------------------------------------------------------------------
page_exec = vm.Page(
title="Executive View",
layout=vm.Layout(
grid=[
[0, 0],
[1, 2],
[1, 2],
[1, 3],
[1, 3],
],
),
components=[
kpi_banner,
bar_charts_tabbed,
vm.Graph(figure=line(data_frame=df_complaints, y="Complaint ID", x="Year-Month Received")),
vm.Graph(
figure=pie(
data_frame=df_complaints[df_complaints["Company response - Closed"] != "Not closed"],
custom_order=[
"Closed with explanation",
"Closed without relief",
"Closed with non-monetary relief",
"Closed with relief",
"Closed with monetary relief",
],
values="Complaint ID",
names="Company response - Closed",
title="Closed company responses",
)
),
],
)
page_region = vm.Page(
title="Regional View",
layout=vm.Layout(grid=[[0, 0]] + [[1, 2]] * 4),
components=[
vm.Card(
text="""
##### Click on a state inside the map to filter the bar charts on the right.
- Which state has the most complaints?
- What are the three biggest issues in California?
- What is the product with the most complaints in Texas?
"""
),
vm.Graph(
figure=choropleth(
data_frame=df_complaints,
locations="State",
color="Complaint ID",
title="Complaints by State",
custom_data=["State"],
),
actions=[
vm.Action(
function=filter_interaction(targets=["regional-issue", "regional-product"]),
)
],
),
vm.Tabs(
tabs=[
vm.Container(
title="By Issue",
components=[
vm.Graph(
id="regional-issue",
figure=bar(
data_frame=df_complaints,
y="Issue",
x="Complaint ID",
),
)
],
),
vm.Container(
title="By Product",
components=[
vm.Graph(
id="regional-product",
figure=bar(
data_frame=df_complaints,
y="Product",
x="Complaint ID",
),
)
],
),
],
),
],
controls=[
vm.Filter(column="Region", selector=vm.Checklist()),
vm.Filter(column="State"),
vm.Filter(column="Product"),
vm.Filter(column="Issue"),
],
)
page_table = vm.Page(
title="List of complaints",
components=[
vm.AgGrid(
figure=dash_ag_grid(
data_frame=df_complaints,
columnDefs=COLUMN_DEFS,
dashGridOptions={"pagination": True},
)
)
],
)
dashboard = vm.Dashboard(
pages=[page_exec, page_region, page_table],
title="Cumulus Financial Corporation",
navigation=vm.Navigation(
nav_selector=vm.NavBar(
items=[
vm.NavLink(label="Executive View", icon="Leaderboard", pages=["Executive View"]),
vm.NavLink(label="Regional View", icon="South America", pages=["Regional View"]),
vm.NavLink(label="Table View", icon="Table View", pages=["List of complaints"]),
]
)
),
)
app = Vizro().build(dashboard)
server = app.dash.server
if __name__ == "__main__":
app.run() |