-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·298 lines (246 loc) · 11.3 KB
/
app.py
File metadata and controls
executable file
·298 lines (246 loc) · 11.3 KB
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
################################################
# Packages
################################################
import panel as pn
from panel.viewable import Viewer
from app_utils import styles, traces, indicators, logos
from app_components import mod_select, paramztn_select, settings_tabs, param_summary, color_panel, plots, code_display
################################################
# Initialize Panel
################################################
# Extensions and themes used by panel
pn.extension('tabulator', 'plotly', 'codeeditor', 'floatpanel', design = styles.THEMES['page_design'])
pn.config.theme = styles.THEMES['page_theme']
pn.config.raw_css.append(styles.PAGE_RAW_CSS)
################################################
# Dashboard - Layout
################################################
class Dashboard(Viewer):
def __init__(self, paramztn_info, **params):
# Note: the order in which the components are instantiated will determine precedence for updates that have the same dependency
# Parameter section
self.paramztn_info = paramztn_info
self.settings_tabs = settings_tabs.SettingsTabs(paramztn_info = self.paramztn_info)
super().__init__(**params)
self.param_summary = param_summary.ParamSummary(paramztn_info = self.paramztn_info, settings_info = self.settings_tabs)
self.param_row = pn.FlexBox(
self.param_summary,
self.settings_tabs,
gap = '0.5%',
flex_wrap = 'nowrap',
styles = {'height':'35%'}
)
# Trace information
self.trace_info = traces.AllTraceInfo(paramztn_info = self.paramztn_info, settings_info = self.settings_tabs)
# Color information
self.color_panel = color_panel.ColorPanel(settings_info = self.settings_tabs, trace_info = self.trace_info)
# Plot section
self.plot_panel = plots.PlotPanel(paramztn_info = self.paramztn_info, settings_info = self.settings_tabs,
trace_info = self.trace_info, clr_info = self.color_panel)
# Code section
self.code_panel = code_display.CodePanel(paramztn_info = self.paramztn_info, settings_info = self.settings_tabs,
trace_info = self.trace_info, clr_info = self.color_panel)
self.main_content = pn.FlexBox(
self.plot_panel,
self.code_panel,
flex_wrap = 'nowrap',
gap = '0.5%',
styles = {'height':'100%',
'width':'100%',
'z-index':'100',
'position':'absolute'}
)
self.main_row = pn.FlexBox(
self.main_content,
self.color_panel,
styles = {'height':'64%',
'width':'100%'}
)
# Entire dashboard layout
self.db_components = self.set_db_components()
self.dashboard_layout = pn.FlexBox(
gap = '1%',
flex_direction = 'column',
align_content = 'center'
)
def set_db_components(self):
db_components = {}
# Set labels for plot boxes
for name in styles.ALL_PLOT_NAMES:
db_components[name] = self.plot_panel.plot_boxes[name]
# Set label for summary and code display
db_components['summary'] = self.param_summary.summary_layout
db_components['code'] = self.code_panel.code_layout
return db_components
@pn.depends('paramztn_info.selected_paramztn', watch = True)
def _hide_show(self):
'''
Note: Use .clear() and populate the dashboard instead of .visible = True/False.
This is because scroll-bar resets and other styling updates for components don't seem to work when .visible = False.
'''
if self.paramztn_info.selected_paramztn == None:
self.dashboard_layout.clear()
self.dashboard_layout.styles = {}
else:
# Note: 'set_default_tabs' leads to 'trigger_param_change', which will update everything else (e.g. plots, summary table, etc.)
# Note: 'selected_paramztn' dependency of set_default_tabs could also be put in settings_tabs.py,
# but I chose to put it here to update everything before dashboard gets populated. This is the same with 'set_loading_layout' and 'reset_scroll'.
self.dashboard_layout.objects = [indicators.get_indicator('startup')]
self.param_summary.reset_scroll()
self.code_panel.reset_scroll()
self.plot_panel.set_loading_layout()
self.settings_tabs.set_default_tabs()
self.dashboard_layout.styles = {
'min-height':'500px',
'max-height':'1500px',
'height':'100vh',
}
self.dashboard_layout.objects = [self.main_row, self.param_row]
@pn.depends('settings_tabs.dashboard_checkbox.value', watch = True)
def _update_layout(self, *event):
self.plot_panel.set_loading_layout()
unchecked_components = set(self.db_components.keys()) - set(self.settings_tabs.dashboard_checkbox.value)
checked_plots = list(set(self.settings_tabs.dashboard_checkbox.value) - {'summary', 'code'})
for key in self.settings_tabs.dashboard_checkbox.value:
self.db_components[key].visible = True
for key in unchecked_components:
self.db_components[key].visible = False
# Check for summary
if 'summary' in self.settings_tabs.dashboard_checkbox.value:
self.settings_tabs.tabs_layout.tabs_location = 'above'
else:
self.settings_tabs.tabs_layout.tabs_location = 'left'
# Check for number of plots and if code is displayed
plot_code_bool = [len(checked_plots) > 0, 'code' in self.settings_tabs.dashboard_checkbox.value]
if True in plot_code_bool:
match plot_code_bool:
# At least 1 plot, and code displayed
case [True, True]:
for box in self.plot_panel.plot_boxes.values():
box.styles = styles.EXPANDED_PLOTBOX_STYLES
# This is a makeshift way to reset the scroll on the plot_layout flexbox
# There may be a better way to do this without JS
self.plot_panel.plot_layout.append(None)
# At least 1 plot, and code not displayed
case [True, False]:
# More than 1 plot
if len(checked_plots) > 1:
for box in self.plot_panel.plot_boxes.values():
box.styles = styles.BASE_PLOTBOX_STYLES
# Single plot
else:
self.db_components[checked_plots[0]].styles = styles.EXPANDED_PLOTBOX_STYLES
# Note: Nothing extra is done if no plots and code is displayed
self.param_row.styles = {'height':'35%'}
self.main_row.visible = True
self.plot_panel.plot_layout.visible = plot_code_bool[0]
self.code_panel.visible = plot_code_bool[1]
# Hide main row and expand param row
elif 'code' not in self.settings_tabs.dashboard_checkbox.value:
self.param_row.styles = {'height':'100%'}
self.main_row.visible = False
def __panel__(self):
return self.dashboard_layout
################################################
# App Layout
################################################
class BAGLECalc(Viewer):
def __init__(self, **params):
self.mod_row = mod_select.ModSelect()
self.paramztn_row = paramztn_select.ParamztnSelect(mod_info = self.mod_row)
self.dashboard = Dashboard(paramztn_info = self.paramztn_row)
self.page_title = pn.pane.HTML(
object = f'''
<span style="color:{styles.CLRS['txt_primary']};font-size:{styles.FONTSIZES['page_title']}; font-weight:600;">
BAGLE Calculator
</span>
''',
styles = {'align-content':'center',
'text-align':'center',
'height':'100%',
'width':'100%',
'margin':'0',
'position':'absolute',
'z-index':'-100'}
)
self.title_layout = pn.FlexBox(
logos.ALL_LOGOS['mulab'],
self.page_title,
logos.ALL_LOGOS['github'],
flex_direction = 'row',
justify_content = 'space-between',
align_items = 'center',
styles = {'width':'100%', 'margin-bottom':'-0.4rem'}
)
# Model header
self.mod_header = pn.widgets.StaticText(
value = 'Model:',
align = 'end',
styles = {'font-size': styles.FONTSIZES['page_header'],
'font-weight': '550',
'margin-bottom': '1rem'}
)
# Parameterization Header
self.paramztn_header = pn.widgets.StaticText(
value = f'Parameterization:',
align = 'end',
styles = {'font-size': styles.FONTSIZES['page_header'],
'font-weight': '550',
'margin-top': '0'}
)
self.select_title_col = pn.Column(
self.mod_header,
self.paramztn_header,
styles = {'margin-top':'-0.08rem'}
)
self.select_widget_col = pn.Column(
self.mod_row,
self.paramztn_row,
styles = {'width':'70%'}
)
# Layout for model and parameterization selection rows
self.selection_layout = pn.FlexBox(
self.select_title_col,
self.select_widget_col,
flex_direction = 'row',
justify_content = 'center',
styles = {'margin-bottom': '-0.2rem'}
)
# Content layout for parge title and selection widgets (model/parameterization)
self.header_content = pn.FlexBox(
self.title_layout,
pn.layout.Divider(),
self.selection_layout,
pn.layout.Divider(),
styles = {'max-width':'1500px', 'margin-top':'0.2%'}
)
# Content layout for entire page
self.page_content = pn.FlexBox(
self.header_content,
self.dashboard,
flex_direction = 'column',
align_items = 'center',
align_content = 'center',
styles = {'width': '100%',
'padding-left':'2%',
'padding-right':'2%',
'min-width':'1000px',
'max-width':'2500px',
'height':'fit-content',
'overflow-y':'scroll'}
)
self.page_layout = pn.Row(
pn.HSpacer(),
self.page_content,
pn.HSpacer(),
styles = {'overflow-y':'hidden',
'overflow-x':'scroll'}
)
def __panel__(self):
# Center content
return self.page_layout
################################################
# Serve App
################################################
# Used to serve with panel serve in command line
BAGLECalc().servable(title = 'BAGLE Calculator')