Spaces:
Running
Running
Commit
Β·
1e4d086
1
Parent(s):
c62cec4
Convert pages to dictionary with nav icons as values
Browse filesReplace separate pages list and nav_icons list with a single dictionary
mapping page objects to their navigation icons for clearer association.
π€ Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -65,7 +65,7 @@ def create_kpi_card_figure(data_frame, title, icon, metric_value=None, is_curren
|
|
| 65 |
title=title,
|
| 66 |
icon=icon,
|
| 67 |
),
|
| 68 |
-
actions=va.set_control(control="metric", value=metric_value)
|
| 69 |
)
|
| 70 |
|
| 71 |
|
|
@@ -103,12 +103,11 @@ overview_page = vm.Page(
|
|
| 103 |
create_kpi_card_figure(order_kpi_df, "Orders", "orders", metric_value="Order ID", is_currency=False),
|
| 104 |
create_kpi_card_figure(
|
| 105 |
customer_kpi_df, "Customers", "group", metric_value="Customer ID", is_currency=False
|
| 106 |
-
)
|
| 107 |
],
|
| 108 |
),
|
| 109 |
create_chart_container_with_nav(
|
| 110 |
-
id="line_month",
|
| 111 |
-
figure=create_line_chart_per_month(superstore_df, value_col="Sales")
|
| 112 |
),
|
| 113 |
create_chart_container_with_nav(
|
| 114 |
id="order_status",
|
|
@@ -129,7 +128,7 @@ overview_page = vm.Page(
|
|
| 129 |
id="category_bar",
|
| 130 |
figure=create_bar_current_vs_previous_category(superstore_df, value_col="Sales"),
|
| 131 |
nav_href="/products",
|
| 132 |
-
)
|
| 133 |
],
|
| 134 |
controls=[
|
| 135 |
vm.Parameter(
|
|
@@ -160,22 +159,17 @@ regions_page = vm.Page(
|
|
| 160 |
id="region_map_chart",
|
| 161 |
header="π‘ Click on a state to filter charts on the right.",
|
| 162 |
figure=create_map_bubble_new(superstore_df, value_col="Sales", custom_data=["State_Code"]),
|
| 163 |
-
actions=va.set_control(control="state_filter", value="State_Code")
|
| 164 |
)
|
| 165 |
],
|
| 166 |
-
variant="filled"
|
| 167 |
),
|
| 168 |
vm.Container(
|
| 169 |
-
components=[
|
| 170 |
-
vm.Graph(
|
| 171 |
-
id="pg2-chart-1",
|
| 172 |
-
figure=bar_chart_top_n(superstore_df, x="Sales", y="City")
|
| 173 |
-
)
|
| 174 |
-
],
|
| 175 |
controls=[
|
| 176 |
vm.Parameter(
|
| 177 |
targets=["pg2-chart-1.top_n"],
|
| 178 |
-
selector=vm.Slider(min=5, max=30, step=5, value=20, title="Choose top N")
|
| 179 |
),
|
| 180 |
vm.Parameter(
|
| 181 |
selector=vm.RadioItems(
|
|
@@ -183,10 +177,10 @@ regions_page = vm.Page(
|
|
| 183 |
title="Choose y-axis",
|
| 184 |
),
|
| 185 |
targets=["pg2-chart-1.y"],
|
| 186 |
-
)
|
| 187 |
],
|
| 188 |
variant="filled",
|
| 189 |
-
)
|
| 190 |
],
|
| 191 |
controls=[
|
| 192 |
vm.Filter(
|
|
@@ -194,14 +188,8 @@ regions_page = vm.Page(
|
|
| 194 |
column="State_Code",
|
| 195 |
visible=False,
|
| 196 |
),
|
| 197 |
-
vm.Filter(
|
| 198 |
-
|
| 199 |
-
selector=vm.Checklist(title="Choose segment")
|
| 200 |
-
),
|
| 201 |
-
vm.Filter(
|
| 202 |
-
column="Category",
|
| 203 |
-
selector=vm.Checklist(title="Choose category")
|
| 204 |
-
),
|
| 205 |
vm.Parameter(
|
| 206 |
selector=vm.RadioItems(
|
| 207 |
options=["Sales", "Profit"],
|
|
@@ -211,7 +199,7 @@ regions_page = vm.Page(
|
|
| 211 |
"region_map_chart.value_col",
|
| 212 |
"pg2-chart-1.x",
|
| 213 |
],
|
| 214 |
-
)
|
| 215 |
],
|
| 216 |
)
|
| 217 |
],
|
|
@@ -230,14 +218,14 @@ customers_page = vm.Page(
|
|
| 230 |
aggrid_df,
|
| 231 |
columnDefs=COLUMN_DEFS_CUSTOMERS,
|
| 232 |
),
|
| 233 |
-
actions=va.set_control(control="pg3_parameter_1", value="Customer Name")
|
| 234 |
),
|
| 235 |
-
vm.Graph(id="pg3_pareto_chart", figure=pareto_customers_chart(superstore_df, highlight_customer=None))
|
| 236 |
],
|
| 237 |
controls=[
|
| 238 |
vm.Filter(column="Region", selector=vm.Checklist(title="Choose region")),
|
| 239 |
vm.Filter(column="Segment", selector=vm.Checklist(title="Choose segment")),
|
| 240 |
-
vm.Filter(column="Category", selector=vm.Checklist(title="Choose category"))
|
| 241 |
],
|
| 242 |
)
|
| 243 |
],
|
|
@@ -256,20 +244,14 @@ products_page = vm.Page(
|
|
| 256 |
title="Products",
|
| 257 |
components=[
|
| 258 |
vm.Container(
|
| 259 |
-
layout=vm.Grid(
|
| 260 |
-
grid=[
|
| 261 |
-
[0, 0, 2, 2],
|
| 262 |
-
[1, 1, 2, 2],
|
| 263 |
-
[1, 1, 2, 2]
|
| 264 |
-
]
|
| 265 |
-
),
|
| 266 |
components=[
|
| 267 |
vm.Container(
|
| 268 |
components=[
|
| 269 |
vm.Graph(
|
| 270 |
id="pg4-chart-1",
|
| 271 |
figure=bar_chart_by_category(superstore_df, custom_data=["Category"]),
|
| 272 |
-
actions=va.set_control(control="pg4-filter-1", value="Category")
|
| 273 |
)
|
| 274 |
],
|
| 275 |
variant="filled",
|
|
@@ -280,7 +262,7 @@ products_page = vm.Page(
|
|
| 280 |
id="table",
|
| 281 |
header="π‘ Click on a row to highlight the data point in the matrix on the right.",
|
| 282 |
figure=dash_ag_grid(superstore_product_df, columnDefs=COLUMN_DEFS_PRODUCT),
|
| 283 |
-
actions=va.set_control(control="pg4_parameter_1", value="Sub-Category")
|
| 284 |
)
|
| 285 |
],
|
| 286 |
variant="filled",
|
|
@@ -294,12 +276,12 @@ products_page = vm.Page(
|
|
| 294 |
x="Sales",
|
| 295 |
y="Profit",
|
| 296 |
custom_data=["Sub-Category"],
|
| 297 |
-
)
|
| 298 |
)
|
| 299 |
],
|
| 300 |
variant="filled",
|
| 301 |
-
)
|
| 302 |
-
]
|
| 303 |
)
|
| 304 |
],
|
| 305 |
controls=[
|
|
@@ -320,7 +302,7 @@ products_page = vm.Page(
|
|
| 320 |
targets=["pg4-chart-3.highlight_sub_category"],
|
| 321 |
selector=vm.Dropdown(options=subcategories, value="NONE", multi=False),
|
| 322 |
visible=False,
|
| 323 |
-
)
|
| 324 |
],
|
| 325 |
)
|
| 326 |
|
|
@@ -330,32 +312,30 @@ orders_page = vm.Page(
|
|
| 330 |
components=[
|
| 331 |
vm.AgGrid(id="table_id", figure=custom_orders_aggrid(superstore_df)),
|
| 332 |
vm.Button(
|
| 333 |
-
text="Export data",
|
| 334 |
-
|
| 335 |
-
actions=va.export_data(targets=["table_id"], file_format="xlsx")
|
| 336 |
-
)
|
| 337 |
],
|
| 338 |
)
|
| 339 |
|
| 340 |
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
|
| 349 |
navigation = vm.Navigation(
|
| 350 |
-
pages=[
|
| 351 |
nav_selector=vm.NavBar(
|
| 352 |
-
items=[vm.NavLink(pages=[page], label=page, icon=icon) for page, icon in
|
| 353 |
),
|
| 354 |
)
|
| 355 |
|
| 356 |
dashboard = vm.Dashboard(
|
| 357 |
title="Superstore dashboard",
|
| 358 |
-
pages=
|
| 359 |
navigation=navigation,
|
| 360 |
theme="vizro_light",
|
| 361 |
)
|
|
|
|
| 65 |
title=title,
|
| 66 |
icon=icon,
|
| 67 |
),
|
| 68 |
+
actions=va.set_control(control="metric", value=metric_value),
|
| 69 |
)
|
| 70 |
|
| 71 |
|
|
|
|
| 103 |
create_kpi_card_figure(order_kpi_df, "Orders", "orders", metric_value="Order ID", is_currency=False),
|
| 104 |
create_kpi_card_figure(
|
| 105 |
customer_kpi_df, "Customers", "group", metric_value="Customer ID", is_currency=False
|
| 106 |
+
),
|
| 107 |
],
|
| 108 |
),
|
| 109 |
create_chart_container_with_nav(
|
| 110 |
+
id="line_month", figure=create_line_chart_per_month(superstore_df, value_col="Sales")
|
|
|
|
| 111 |
),
|
| 112 |
create_chart_container_with_nav(
|
| 113 |
id="order_status",
|
|
|
|
| 128 |
id="category_bar",
|
| 129 |
figure=create_bar_current_vs_previous_category(superstore_df, value_col="Sales"),
|
| 130 |
nav_href="/products",
|
| 131 |
+
),
|
| 132 |
],
|
| 133 |
controls=[
|
| 134 |
vm.Parameter(
|
|
|
|
| 159 |
id="region_map_chart",
|
| 160 |
header="π‘ Click on a state to filter charts on the right.",
|
| 161 |
figure=create_map_bubble_new(superstore_df, value_col="Sales", custom_data=["State_Code"]),
|
| 162 |
+
actions=va.set_control(control="state_filter", value="State_Code"),
|
| 163 |
)
|
| 164 |
],
|
| 165 |
+
variant="filled",
|
| 166 |
),
|
| 167 |
vm.Container(
|
| 168 |
+
components=[vm.Graph(id="pg2-chart-1", figure=bar_chart_top_n(superstore_df, x="Sales", y="City"))],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
controls=[
|
| 170 |
vm.Parameter(
|
| 171 |
targets=["pg2-chart-1.top_n"],
|
| 172 |
+
selector=vm.Slider(min=5, max=30, step=5, value=20, title="Choose top N"),
|
| 173 |
),
|
| 174 |
vm.Parameter(
|
| 175 |
selector=vm.RadioItems(
|
|
|
|
| 177 |
title="Choose y-axis",
|
| 178 |
),
|
| 179 |
targets=["pg2-chart-1.y"],
|
| 180 |
+
),
|
| 181 |
],
|
| 182 |
variant="filled",
|
| 183 |
+
),
|
| 184 |
],
|
| 185 |
controls=[
|
| 186 |
vm.Filter(
|
|
|
|
| 188 |
column="State_Code",
|
| 189 |
visible=False,
|
| 190 |
),
|
| 191 |
+
vm.Filter(column="Segment", selector=vm.Checklist(title="Choose segment")),
|
| 192 |
+
vm.Filter(column="Category", selector=vm.Checklist(title="Choose category")),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
vm.Parameter(
|
| 194 |
selector=vm.RadioItems(
|
| 195 |
options=["Sales", "Profit"],
|
|
|
|
| 199 |
"region_map_chart.value_col",
|
| 200 |
"pg2-chart-1.x",
|
| 201 |
],
|
| 202 |
+
),
|
| 203 |
],
|
| 204 |
)
|
| 205 |
],
|
|
|
|
| 218 |
aggrid_df,
|
| 219 |
columnDefs=COLUMN_DEFS_CUSTOMERS,
|
| 220 |
),
|
| 221 |
+
actions=va.set_control(control="pg3_parameter_1", value="Customer Name"),
|
| 222 |
),
|
| 223 |
+
vm.Graph(id="pg3_pareto_chart", figure=pareto_customers_chart(superstore_df, highlight_customer=None)),
|
| 224 |
],
|
| 225 |
controls=[
|
| 226 |
vm.Filter(column="Region", selector=vm.Checklist(title="Choose region")),
|
| 227 |
vm.Filter(column="Segment", selector=vm.Checklist(title="Choose segment")),
|
| 228 |
+
vm.Filter(column="Category", selector=vm.Checklist(title="Choose category")),
|
| 229 |
],
|
| 230 |
)
|
| 231 |
],
|
|
|
|
| 244 |
title="Products",
|
| 245 |
components=[
|
| 246 |
vm.Container(
|
| 247 |
+
layout=vm.Grid(grid=[[0, 0, 2, 2], [1, 1, 2, 2], [1, 1, 2, 2]]),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
components=[
|
| 249 |
vm.Container(
|
| 250 |
components=[
|
| 251 |
vm.Graph(
|
| 252 |
id="pg4-chart-1",
|
| 253 |
figure=bar_chart_by_category(superstore_df, custom_data=["Category"]),
|
| 254 |
+
actions=va.set_control(control="pg4-filter-1", value="Category"),
|
| 255 |
)
|
| 256 |
],
|
| 257 |
variant="filled",
|
|
|
|
| 262 |
id="table",
|
| 263 |
header="π‘ Click on a row to highlight the data point in the matrix on the right.",
|
| 264 |
figure=dash_ag_grid(superstore_product_df, columnDefs=COLUMN_DEFS_PRODUCT),
|
| 265 |
+
actions=va.set_control(control="pg4_parameter_1", value="Sub-Category"),
|
| 266 |
)
|
| 267 |
],
|
| 268 |
variant="filled",
|
|
|
|
| 276 |
x="Sales",
|
| 277 |
y="Profit",
|
| 278 |
custom_data=["Sub-Category"],
|
| 279 |
+
),
|
| 280 |
)
|
| 281 |
],
|
| 282 |
variant="filled",
|
| 283 |
+
),
|
| 284 |
+
],
|
| 285 |
)
|
| 286 |
],
|
| 287 |
controls=[
|
|
|
|
| 302 |
targets=["pg4-chart-3.highlight_sub_category"],
|
| 303 |
selector=vm.Dropdown(options=subcategories, value="NONE", multi=False),
|
| 304 |
visible=False,
|
| 305 |
+
),
|
| 306 |
],
|
| 307 |
)
|
| 308 |
|
|
|
|
| 312 |
components=[
|
| 313 |
vm.AgGrid(id="table_id", figure=custom_orders_aggrid(superstore_df)),
|
| 314 |
vm.Button(
|
| 315 |
+
text="Export data", icon="download", actions=va.export_data(targets=["table_id"], file_format="xlsx")
|
| 316 |
+
),
|
|
|
|
|
|
|
| 317 |
],
|
| 318 |
)
|
| 319 |
|
| 320 |
|
| 321 |
+
pages = {
|
| 322 |
+
overview_page: "Home",
|
| 323 |
+
regions_page: "Globe Asia",
|
| 324 |
+
products_page: "Barcode",
|
| 325 |
+
customers_page: "Group",
|
| 326 |
+
orders_page: "Shopping Cart",
|
| 327 |
+
}
|
| 328 |
|
| 329 |
navigation = vm.Navigation(
|
| 330 |
+
pages=[page.title for page in pages.keys()],
|
| 331 |
nav_selector=vm.NavBar(
|
| 332 |
+
items=[vm.NavLink(pages=[page.title], label=page.title, icon=icon) for page, icon in pages.items()]
|
| 333 |
),
|
| 334 |
)
|
| 335 |
|
| 336 |
dashboard = vm.Dashboard(
|
| 337 |
title="Superstore dashboard",
|
| 338 |
+
pages=list(pages.keys()),
|
| 339 |
navigation=navigation,
|
| 340 |
theme="vizro_light",
|
| 341 |
)
|