import pandas as pd
import vizro.models as vm
from dash import html
from vizro import Vizro
from vizro.managers import data_manager
from vizro.models.types import capture
import spec_dashboard
#### DATA SETUP ####
# Our custom React components have data embedded, so we use a dummy DataFrame
# to satisfy Vizro's data_frame requirement.
dummy_df = pd.DataFrame({"_placeholder": [0]})
data_manager["shift_data"] = dummy_df
data_manager["production_data"] = dummy_df
data_manager["quality_data"] = dummy_df
#### CUSTOM FIGURE SETUP ####
@capture("figure")
def shift_overview_figure(
data_frame: pd.DataFrame,
production_metric: str = "mined",
) -> html.Div:
"""Shift Overview page — wraps the custom React component with KPIs, charts, gauge, and risk table."""
return html.Div(
spec_dashboard.ShiftOverviewContent(
id="shift-overview-react",
production_metric=production_metric,
),
style={"width": "100%"},
)
@capture("figure")
def production_equipment_figure(
data_frame: pd.DataFrame,
equipment_type: str = "All",
equipment_status: str = "All",
) -> html.Div:
"""Production & Equipment page — wraps the custom React component with funnel, queue, scatter, tables."""
all_types = ["Shovel", "Truck"]
all_statuses = ["Operating", "Down", "Standby", "Maintenance"]
types_list = all_types if equipment_type == "All" else [equipment_type]
statuses_list = all_statuses if equipment_status == "All" else [equipment_status]
return html.Div(
spec_dashboard.ProductionEquipmentContent(
id="production-equipment-react",
selected_types=types_list,
selected_statuses=statuses_list,
),
style={"width": "100%"},
)
@capture("figure")
def grade_quality_figure(
data_frame: pd.DataFrame,
selected_source: str = "All Pits",
selected_metric: str = "fe",
view_mode: str = "all",
) -> html.Div:
"""Grade & Quality page — wraps the custom React component with waterfall, trend, anomaly table, box plot."""
return html.Div(
spec_dashboard.GradeQualityContent(
id="grade-quality-react",
selected_source=selected_source,
selected_metric=selected_metric,
view_mode=view_mode,
),
style={"width": "100%"},
)
#### DASHBOARD SETUP ####
shift_overview_page = vm.Page(
title="Shift Overview",
path="/",
components=[
vm.Figure(
id="shift-overview",
figure=shift_overview_figure(data_frame="shift_data"),
),
],
controls=[
vm.Parameter(
targets=["shift-overview.production_metric"],
selector=vm.RadioItems(
title="Production Metric",
options=[
{"label": "Mined", "value": "mined"},
{"label": "Crushed", "value": "crushed"},
{"label": "Shipped", "value": "shipped"},
],
value="mined",
),
),
],
)
production_equipment_page = vm.Page(
title="Production & Equipment",
path="/production",
components=[
vm.Figure(
id="production-equipment",
figure=production_equipment_figure(data_frame="production_data"),
),
],
controls=[
vm.Parameter(
targets=["production-equipment.equipment_type"],
selector=vm.Dropdown(
title="Equipment Type",
options=[
{"label": "All Types", "value": "All"},
{"label": "Shovels", "value": "Shovel"},
{"label": "Trucks", "value": "Truck"},
],
value="All",
multi=False,
),
),
vm.Parameter(
targets=["production-equipment.equipment_status"],
selector=vm.Dropdown(
title="Equipment Status",
options=[
{"label": "All Statuses", "value": "All"},
{"label": "Operating", "value": "Operating"},
{"label": "Down", "value": "Down"},
{"label": "Standby", "value": "Standby"},
{"label": "Maintenance", "value": "Maintenance"},
],
value="All",
multi=False,
),
),
],
)
grade_quality_page = vm.Page(
title="Grade & Quality",
path="/quality",
components=[
vm.Figure(
id="grade-quality",
figure=grade_quality_figure(data_frame="quality_data"),
),
],
controls=[
vm.Parameter(
targets=["grade-quality.selected_source"],
selector=vm.Dropdown(
title="Source",
options=[
{"label": "All Pits", "value": "All Pits"},
{"label": "Pit 1 - North", "value": "Pit 1 - North"},
{"label": "Pit 2 - Central", "value": "Pit 2 - Central"},
{"label": "Pit 3 - South", "value": "Pit 3 - South"},
],
value="All Pits",
multi=False,
),
),
vm.Parameter(
targets=["grade-quality.selected_metric"],
selector=vm.Dropdown(
title="Quality Metric",
options=[
{"label": "Fe", "value": "fe"},
{"label": "SiO\u2082", "value": "sio2"},
{"label": "Al\u2082O\u2083", "value": "al2o3"},
{"label": "P", "value": "p"},
{"label": "Moisture", "value": "moisture"},
],
value="fe",
multi=False,
),
),
vm.Parameter(
targets=["grade-quality.view_mode"],
selector=vm.RadioItems(
title="View Mode",
options=[
{"label": "All Data", "value": "all"},
{"label": "Anomalies Only", "value": "anomalies"},
],
value="all",
),
),
],
)
dashboard = vm.Dashboard(
title="Open Pit Monitor",
pages=[shift_overview_page, production_equipment_page, grade_quality_page],
theme="vizro_light",
)
app = Vizro().build(dashboard)
if __name__ == "__main__":
app.run(port=8050, debug=True)