Py.Cafe

lingyielia/

vizro-from-lovable

Exploring Vizro with Iris

DocsPricing
  • spec_dashboard/
  • app.py
  • requirements.txt
app.py
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
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)