-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
202 lines (187 loc) · 8.92 KB
/
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
import dash
import dash_auth
from dash import html, dcc, Input, Output, ctx, State
import logging
from src.scripts import create_fy_options, get_marks
import json
from config import settings
LOGGING_LEVEL = settings['LOGGING_LEVEL']
logging.basicConfig(level=LOGGING_LEVEL)
FY_OPTIONS = create_fy_options()
app = dash.Dash(__name__, use_pages=True, prevent_initial_callbacks='initial_duplicate',
suppress_callback_exceptions=True, title='UTRC Dashboard')
with open('./assets/data/accounts.txt') as f:
data = f.read()
ACCOUNTS = json.loads(data)
dash_auth.BasicAuth(app, ACCOUNTS)
app.layout = html.Div([
html.Div(
[
html.A(html.Img(src='assets/images/utrc-horizontal-logo-white-simple.svg', className='utrc-logo'), href='https://utrc.tacc.utexas.edu/'),
html.A("Users", href='/'),
html.A("Allocations", href='/allocations'),
html.A("Usage", href='/usage'),
],
id='header2'
),
html.Div([
html.Button('Toggle Filters', id='toggle-filters', n_clicks=0),
html.Div([
html.Div([
"By institution:",
html.Div([
html.Div(["?", html.Span(html.P(children=["UTAus: The University of Texas at Austin", html.Br(),
"UTA: The University of Texas at Arlington", html.Br(),
"UTD: The University of Texas at Dallas", html.Br(),
"UTEP: The University of Texas at El Paso", html.Br(),
"UTPB: The University of Texas Permian Basin", html.Br(),
"UTRGV: The University of Texas Rio Grande Valley", html.Br(),
"UTSA: The University of Texas at San Antonio", html.Br(),
"UTT: The University of Texas at Tyler", html.Br(),
"UTHSC-H: The University of Texas Health Science Center-Houston", html.Br(),
"UTHSC-SA: The University of Texas Health Science Center-San Antonio", html.Br(),
"UTMB: The University of Texas Medical Branch", html.Br(),
"UTMDA: The University of Texas MD Anderson Cancer Center", html.Br(),
"UTSW: The University of Texas Southwestern Medical Center", html.Br(),
"UTSYS: The University of Texas Systems"]),
className='tooltiptext')
], className='tooltip'),
dcc.Checklist(
id="all-or-none-inst",
options=[{"label": "Select All", "value": "All"}],
value=[],
className='select-all'
),
dcc.Checklist(
id='select_institutions_checklist',
options=[
{'label': 'UTAus', 'value': 'UTAus'},
{'label': 'UTA', 'value': 'UTA'},
{'label': 'UTD', 'value': 'UTD'},
{'label': 'UTEP', 'value': 'UTEP'},
{'label': 'UTPB', 'value': 'UTPB'},
{'label': 'UTRGV', 'value': 'UTRGV'},
{'label': 'UTSA', 'value': 'UTSA'},
{'label': 'UTT', 'value': 'UTT'},
{'label': 'UTHSC-H', 'value': 'UTHSC-H'},
{'label': 'UTHSC-SA', 'value': 'UTHSC-SA'},
{'label': 'UTMB', 'value': 'UTMB'},
{'label': 'UTMDA', 'value': 'UTMDA'},
{'label': 'UTSW', 'value': 'UTSW'},
{'label': 'UTSYS', 'value': 'UTSYS'}
],
value=['UTA', 'UTHSC-SA', 'UTSW', 'UTHSC-H', 'UTMDA', 'UTRGV', 'UTMB', 'UTD', 'UTSA', 'UTEP', 'UTT', 'UTSYS', 'UTPB'],
persistence=True,
persistence_type='session'
),], className='single_line_checklist'),
], id='select_institutions_div', className='filter_div'),
html.Div([
"By machine:",
html.Div([
dcc.Checklist(
id="all-or-none-machine",
options=[{"label": "Select All", "value": "All"}],
value=["All"],
className='select-all'
),
dcc.Checklist(
id='select_machine_checklist',
options=[
{'label': 'Lonestar6', 'value': 'Lonestar6'},
{'label': 'Frontera', 'value': 'Frontera'},
{'label': 'Longhorn3', 'value': 'Longhorn3'},
{'label': 'Stampede4', 'value': 'Stampede4'},
{'label': 'Lonestar5', 'value': 'Lonestar5'},
{'label': 'Maverick3', 'value': 'Maverick3'},
{'label': 'Jetstream', 'value': 'Jetstream'},
{'label': 'Hikari', 'value': 'Hikari'}
],
value=['Lonestar6', 'Frontera', 'Longhorn3', 'Stampede4', 'Lonestar5', 'Maverick3', 'Jetstream', 'Hikari'],
persistence=True,
persistence_type='session'
),], className='single_line_checklist'),
], id='select_machine_div', className='filter_div'),
html.Div([
"By fiscal year:",
dcc.RadioItems(id='year_radio_dcc',
options=FY_OPTIONS,
value='21-22',
inline=True,
persistence=True,
persistence_type='session')], id='year_radio_box', className='filter_div'),
html.Div([
"By month:",
dcc.RangeSlider(id='date_filter',
value=[0, 12],
step=None,
marks={0: '21-09',
1: '21-10',
2: '21-11',
3: '21-12',
4: '22-01',
5: '22-02',
6: '22-03',
7: '22-04',
8: '22-05',
9: '22-06',
10: '22-07',
11: '22-08'},
min=0,
max=11,
persistence=True,
persistence_type='session')
], id='date_range_selector', className='filter_div'),], id='filters', style={'display':''}),
dash.page_container], className='body')
])
for page in dash.page_registry.values():
logging.debug((f"{page['name']} - {page['path']}"))
@app.callback(
Output('filters', 'style'),
Input('toggle-filters', 'n_clicks'),
State('filters', 'style'), prevent_initial_call=True
)
def toggle_filters(click, state):
if state == {'display':'none'}:
return {'display':''}
else:
return {'display':'none'}
@app.callback(
Output("select_institutions_checklist", "value"),
[Input("all-or-none-inst", "value")],
[State("select_institutions_checklist", "options")], prevent_initial_call=True,
)
def select_all_none(all_selected, options):
all_or_none = []
all_or_none = [option["value"] for option in options if all_selected]
return all_or_none
@app.callback(
Output("select_machine_checklist", "value"),
[Input("all-or-none-machine", "value")],
[State("select_machine_checklist", "options")], prevent_initial_call=True,
)
def select_all_none(all_selected, options):
all_or_none = []
all_or_none = [option["value"] for option in options if all_selected]
return all_or_none
@app.callback(
Output('date_range_selector', 'children'),
Input('date_filter', 'value'),
Input('year_radio_dcc', 'value')
)
def update_date_range(date_range, fiscal_year):
logging.debug(f'Callback trigger id: {ctx.triggered_id}')
marks = get_marks(fiscal_year)
if ctx.triggered_id == 'year_radio_dcc':
logging.debug(f'Marks = {marks}')
slider_children = ["By month:",
dcc.RangeSlider(id='date_filter', value=[0, len(marks)],
step=None, marks=marks, min=0, max=len(marks)-1)]
else:
logging.debug(f'Marks = {marks}')
logging.debug(f'date_range = {date_range}')
slider_children = ["By month:",
dcc.RangeSlider(id='date_filter', value=date_range,
step=None, marks=marks, min=0, max=len(marks)-1)]
return slider_children
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=settings['DEBUG_MODE'])