-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.py
1209 lines (961 loc) · 40.2 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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pathlib
import time
import app_fxns
import pandas as pd
import json
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server
app.config.suppress_callback_exceptions = True
# Path
BASE_PATH = pathlib.Path(__file__).parent.resolve()
DATA_PATH = BASE_PATH.joinpath("data").resolve()
models = ['Logistic (multi-phase)', 'Gaussian (multi-phase)', 'Phase Wave', 'Time series analysis', 'Quadratic', 'Exponential']
######################## DASH APP FUNCTIONS ##################################
app.layout = html.Div([
dcc.Tabs([
dcc.Tab(label='COVID Calculator', children=[
html.Div(
id='df1',
style={'display': 'none'}
),
html.Div(
id='df2',
style={'display': 'none'}
),
html.Div(
id='df3',
style={'display': 'none'}
),
# Banner
html.Div(
id="banner1",
className="banner",
children=[html.Img(src=app.get_asset_url("RUSH_full_color.jpg"),
style={'textAlign': 'left'}),
html.Img(src=app.get_asset_url("plotly_logo.png"),
style={'textAlign': 'right'})],
style={#'width': '100%', 'display': 'inline-block',
#'border-radius': '15px',
#'box-shadow': '1px 1px 1px grey',
'background-color': 'rgb(245, 247, 249)',
#'padding': '10px',
#'margin-bottom': '10px',
#'fontSize':16
},
),
# Left column
html.Div(
id="left-column1",
className="three columns",
children=[app_fxns.description_card1(), app_fxns.generate_control_card1()]
+ [
html.Div(
["initial child"], id="output-clientside1",
style={"display": "none"}
)
],
style={
'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
#'fontSize':16
},
),
# Right column
html.Div(
id="right-column1",
className="nine columns",
children=[
html.Div(
id="Figure1",
children=[dcc.Loading(
id="loading-1",
type="default",
fullscreen=False,
children=[
# Plot of model forecast
html.Div(
id="model_forecasts1",
children=[
html.B("Model Forecasts. Exponential and Quadratic models run quickly." +
" Other models are more intensive and may take several seconds."),
html.Hr(),
dcc.Graph(id="model_forecasts_plot1"),
],
style={'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
'fontSize':16
},
),
],
),],),
html.A('Download CSV', id='model_forecast_link', download="model_forecast_data.csv",
href="",
target="_blank"),
html.Br(),
html.Br(),
html.Div(
id="Table4",
children=[dcc.Loading(
id="loading-7",
type="default",
fullscreen=False,
children=[
html.Div(
id="new_cases1",
children=[
html.B("New and Active Cases"),
html.Hr(),
dcc.Graph(id="new_cases_plot1"),
],
style={'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
'fontSize':16
},
),
],
),],),
html.Br(),
html.Br(),
html.Div(
id="Table1",
children=[dcc.Loading(
id="loading-2",
type="default",
fullscreen=False,
children=[
html.Div(
id="patient_census1",
children=[
html.B("Forecasted Patient Census"),
html.Hr(),
dcc.Graph(id="patient_census_plot1"),
],
style={'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
'fontSize':16
},
),
],
),],),
html.Br(),
html.Br(),
html.Div(
id="Figure2",
children=[dcc.Loading(
id="loading-3",
type="default",
fullscreen=False,
children=[
html.Div(
id="patient_discharge1",
children=[
html.B("Forecasted Patient Discharges"),
html.Hr(),
dcc.Graph(id="patient_discharge_plot1"),
],
style={'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
'fontSize':16
},
),
],
),],),
html.Br(),
html.Br(),
html.Div(
id="Table2",
children=[dcc.Loading(
id="loading-4",
type="default",
fullscreen=False,
children=[
html.Div(
id="patient_census_table1",
children=[
html.B("Patient Census and Discharge Table"),
html.Hr(),
dcc.Graph(id="patient_census_table_plot1"),
],
style={'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
'fontSize':16
},
),
],
),],),
html.A('Download CSV', id='Patient_Census_Discharge_link', download="Patient_Census_Discharge_data.csv",
href="",
target="_blank"),
html.Br(),
html.Br(),
html.Div(
id="Figure3",
children=[dcc.Loading(
id="loading-5",
type="default",
fullscreen=False,
children=[
html.Div(
id="ppe1",
children=[
html.B("Forecasted PPE Needs"),
html.Hr(),
dcc.Graph(id="ppe_plot1"),
],
style={'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
'fontSize':16
},
),
],
),],),
html.Br(),
html.Br(),
html.Div(
id="Table3",
children=[dcc.Loading(
id="loading-6",
type="default",
fullscreen=False,
children=[
html.Div(
id="ppe_table1",
children=[
html.B("PPE Forecast Table"),
html.Hr(),
dcc.Graph(id="ppe_table_plot1"),
],
style={'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
'fontSize':16
},
),
],
),],),
html.A('Download CSV', id='ppe_link', download="PPE_Forecast_data.csv",
href="",
target="_blank"),
html.Br(),
html.Br(),
],
),
],
),
dcc.Tab(label='Employee Forecasts', children=[
# Banner
html.Div(
id="banner4",
className="banner",
children=[html.Img(src=app.get_asset_url("RUSH_full_color.jpg"),
style={'textAlign': 'left'}),
html.Img(src=app.get_asset_url("plotly_logo.png"),
style={'textAlign': 'right'})],
),
# Left column
html.Div(
id="left-column1b",
className="three columns",
children=[app_fxns.description_card1b(), app_fxns.generate_control_card2()]
+ [
html.Div(
["initial child"], id="output-clientside1b",
style={"display": "none"}
)
],
style={
'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
#'fontSize':16
},
),
# Right column
html.Div(
id="right-column1b",
className="nine columns",
children=[html.Div(
id="employee_fig1",
children=[dcc.Loading(
id="loading-7b",
type="default",
fullscreen=False,
children=[
html.Div(
id="employee_cases1",
children=[
html.B("Forecasts of new and active cases among employees"),
html.Hr(),
dcc.Graph(id="employee_forecast_plot1"),
],
style={'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
'fontSize':16
},
),
],
),],),
html.Br(),
html.Br(),
html.Div(
id="employee_Table1",
children=[dcc.Loading(
id="loading-8b",
type="default",
fullscreen=False,
children=[
html.Div(
id="employee_cases2",
children=[
html.B("Employee Forecast Table"),
html.Hr(),
dcc.Graph(id="employee_forecast_table1"),
],
style={'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
'fontSize':16
},
),
],
),],),
html.A('Download CSV', id='employee_model_forecast_link', download="employee_forecast_data.csv",
href="",
target="_blank"),
html.Br(),
html.Br(),
],
),
]),
dcc.Tab(label='Instructions & Details', children=[
# Banner
html.Div(
id="banner5",
className="banner",
children=[html.Img(src=app.get_asset_url("RUSH_full_color.jpg"),
style={'textAlign': 'left'}),
html.Img(src=app.get_asset_url("plotly_logo.png"),
style={'textAlign': 'right'})],
style={#'width': '100%', 'display': 'inline-block',
#'border-radius': '15px',
#'box-shadow': '1px 1px 1px grey',
'background-color': 'rgb(245, 247, 249)',
#'padding': '10px',
#'margin-bottom': '10px',
#'fontSize':16
},
),
html.Div(
id="ContactInfo-column",
className="twelve columns",
children=[app_fxns.description_card2()]
+ [
html.Div(
["initial child"], id="output-clientside2",
style={"display": "none"}
)
],
style={
'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
#'fontSize':16
},
),
html.Div(
id="Instructions-column",
className="twelve columns",
children=[app_fxns.description_card3()]
+ [
html.Div(
["initial child"], id="output-clientside3",
style={"display": "none"}
)
],
style={
'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
#'fontSize':16
},
),
html.Div(
id="Details-column",
className="twelve columns",
children=[app_fxns.description_card4()]
+ [
html.Div(
["initial child"], id="output-clientside4",
style={"display": "none"}
)
],
style={
'border-radius': '15px',
'box-shadow': '1px 1px 1px grey',
'background-color': '#f0f0f0',
'padding': '10px',
'margin-bottom': '10px',
#'fontSize':16
},
),
]),
]),
])
#########################################################################################
################################ LOADING CALLBACKS ######################################
#########################################################################################
@app.callback(
dash.dependencies.Output('ICU beds1-container', 'children'),
[dash.dependencies.Input('ICU beds1', 'value')])
def update_output1(value):
return 'ICU beds in house: {}'.format(value)
@app.callback(
dash.dependencies.Output('nonICU beds1-container', 'children'),
[dash.dependencies.Input('nonICU beds1', 'value')])
def update_output2(value):
return 'non-ICU beds in house: {}'.format(value)
@app.callback(
dash.dependencies.Output('visits1-container', 'children'),
[dash.dependencies.Input('visits1', 'value')])
def update_output3(value):
return '% of new cases visiting to your hospital: {}'.format(value)
@app.callback(
dash.dependencies.Output('admits1-container', 'children'),
[dash.dependencies.Input('admits1', 'value')])
def update_output4(value):
return '% of visits admitted: {}'.format(value)
@app.callback(
dash.dependencies.Output('percent ICU1-container', 'children'),
[dash.dependencies.Input('percent ICU1', 'value')])
def update_output5(value):
return '% of visits admitted to ICU: {}'.format(value)
@app.callback(
dash.dependencies.Output('transfers1-container', 'children'),
[dash.dependencies.Input('transfers1', 'value')])
def update_output6(value):
return 'Daily number of transfers admitted: {}'.format(value)
@app.callback(
dash.dependencies.Output('percent transferICU1-container', 'children'),
[dash.dependencies.Input('percent transferICU1', 'value')])
def update_output7(value):
return '% of transfers admitted to ICU: {}'.format(value)
@app.callback(
dash.dependencies.Output('on vent1-container', 'children'),
[dash.dependencies.Input('on vent1', 'value')])
def update_output8(value):
return '% of ICU patients on ventilators: {}'.format(value)
@app.callback(
dash.dependencies.Output('non-ICU LOS1-container', 'children'),
[dash.dependencies.Input('non-ICU LOS1', 'value')])
def update_output9(value):
return 'non-ICU length of stay: {}'.format(value)
@app.callback(
dash.dependencies.Output('ICU LOS1-container', 'children'),
[dash.dependencies.Input('ICU LOS1', 'value')])
def update_output10(value):
return 'ICU length of stay: {}'.format(value)
@app.callback(
dash.dependencies.Output('mortality1-container', 'children'),
[dash.dependencies.Input('mortality1', 'value')])
def update_output11(value):
return 'ICU mortality rate: {}'.format(value)
@app.callback(
dash.dependencies.Output('time lag1-container', 'children'),
[dash.dependencies.Input('time lag1', 'value')])
def update_output12(value):
return 'Time lag in hospital visitation: {}'.format(value)
'''
@app.callback(
dash.dependencies.Output('ICU beds1-container', 'children'),
[dash.dependencies.Input('ICU beds1', 'value')])
def update_output1(value):
return 'Relative positivity rate: {}'.format(value)
'''
@app.callback(
dash.dependencies.Output('ICU beds2-container', 'children'),
[dash.dependencies.Input('ICU beds2', 'value')])
def update_output2_1(value):
return 'ICU beds in house: {}'.format(value)
@app.callback(
dash.dependencies.Output('nonICU beds2-container', 'children'),
[dash.dependencies.Input('nonICU beds2', 'value')])
def update_output2_2(value):
return 'non-ICU beds in house: {}'.format(value)
@app.callback(
dash.dependencies.Output('vents in house2-container', 'children'),
[dash.dependencies.Input('vents in house2', 'value')])
def update_output2_3(value):
return 'Ventilators in house: {}'.format(value)
@app.callback(
dash.dependencies.Output('visits2-container', 'children'),
[dash.dependencies.Input('visits2', 'value')])
def update_output2_4(value):
return '% visits to your hospital: {}'.format(value)
@app.callback(
dash.dependencies.Output('admits2-container', 'children'),
[dash.dependencies.Input('admits2', 'value')])
def update_output2_5(value):
return '% of visits admitted: {}'.format(value)
@app.callback(
dash.dependencies.Output('percent ICU2-container', 'children'),
[dash.dependencies.Input('percent ICU2', 'value')])
def update_output2_6(value):
return '% of visits admitted to ICU: {}'.format(value)
@app.callback(
dash.dependencies.Output('transfers2-container', 'children'),
[dash.dependencies.Input('transfers2', 'value')])
def update_output2_7(value):
return 'Daily number of transfers admitted: {}'.format(value)
@app.callback(
dash.dependencies.Output('percent transferICU2-container', 'children'),
[dash.dependencies.Input('percent transferICU2', 'value')])
def update_output2_8(value):
return '% of transfers admitted to ICU: {}'.format(value)
@app.callback(
dash.dependencies.Output('on vent2-container', 'children'),
[dash.dependencies.Input('on vent2', 'value')])
def update_output2_9(value):
return '% of ICU patients on ventilators: {}'.format(value)
@app.callback(
dash.dependencies.Output('non-ICU LOS2-container', 'children'),
[dash.dependencies.Input('non-ICU LOS2', 'value')])
def update_output2_10(value):
return 'non-ICU length of stay: {}'.format(value)
@app.callback(
dash.dependencies.Output('ICU LOS2-container', 'children'),
[dash.dependencies.Input('ICU LOS2', 'value')])
def update_output2_11(value):
return 'ICU length of stay: {}'.format(value)
@app.callback(
dash.dependencies.Output('mortality2-container', 'children'),
[dash.dependencies.Input('mortality2', 'value')])
def update_output2_12(value):
return 'ICU mortality rate: {}'.format(value)
@app.callback(
dash.dependencies.Output('time lag2-container', 'children'),
[dash.dependencies.Input('time lag2', 'value')])
def update_output2_13(value):
return 'Time lag in hospital visitation: {}'.format(value)
@app.callback(
dash.dependencies.Output('GLOVE SURGICAL-container', 'children'),
[dash.dependencies.Input('gloves1', 'value')])
def update_output2_14(value):
return 'GLOVE SURGICAL: {}'.format(value)
@app.callback(
dash.dependencies.Output('GLOVE EXAM NITRILE-container', 'children'),
[dash.dependencies.Input('gloves2', 'value')])
def update_output2_15(value):
return 'GLOVE EXAM NITRILE: {}'.format(value)
@app.callback(
dash.dependencies.Output('GLOVE EXAM VINYL-container', 'children'),
[dash.dependencies.Input('gloves3', 'value')])
def update_output2_16(value):
return 'GLOVE EXAM NITRILE: {}'.format(value)
@app.callback(
dash.dependencies.Output('MASK FACE PROC ANTI FOG-container', 'children'),
[dash.dependencies.Input('mask1', 'value')])
def update_output2_17(value):
return 'MASK FACE PROC ANTI FOG: {}'.format(value)
@app.callback(
dash.dependencies.Output('MASK PROC FLUID RESISTANT-container', 'children'),
[dash.dependencies.Input('mask2', 'value')])
def update_output2_18(value):
return 'MASK PROC FLUID RESISTANT: {}'.format(value)
@app.callback(
dash.dependencies.Output('GOWN ISOLATION XL YELLOW-container', 'children'),
[dash.dependencies.Input('gown1', 'value')])
def update_output2_19(value):
return 'GOWN ISOLATION XL YELLOW: {}'.format(value)
@app.callback(
dash.dependencies.Output('MASK SURG ANTI FOG W/FILM-container', 'children'),
[dash.dependencies.Input('mask3', 'value')])
def update_output2_20(value):
return 'MASK SURG ANTI FOG W/FILM: {}'.format(value)
@app.callback(
dash.dependencies.Output('SHIELD FACE FULL ANTI FOG-container', 'children'),
[dash.dependencies.Input('shield1', 'value')])
def update_output2_21(value):
return 'SHIELD FACE FULL ANTI FOG: {}'.format(value)
@app.callback(
dash.dependencies.Output('RESP PART FILTER REG-container', 'children'),
[dash.dependencies.Input('resp1', 'value')])
def update_output2_22(value):
return 'RESP PART FILTER REG: {}'.format(value)
@app.callback(
dash.dependencies.Output('incidence rate-container', 'children'),
[dash.dependencies.Input('inc_rate', 'value')])
def update_output2_23(value):
return 'COVID positives among your employees is {}'.format(value) + '% of that for the general population'
@app.callback( # Select sub-category
Output('county-select1', 'value'),
[
Input('county-select1', 'options'),
Input('location-select1', 'value'),
],
)
def update_output15(available_options, v2):
return available_options[0]['value']
@app.callback( # Select sub-category
Output('county-select2', 'value'),
[
Input('county-select2', 'options'),
Input('location-select2', 'value'),
],
)
def update_output18(available_options, v2):
return available_options[0]['value']
@app.callback( # Select sub-category
Output('location-select1', 'value'),
[
Input('location-select1', 'options'),
#Input('county-select1', 'value'),
],
)
def update_output16(available_options):
return available_options[0]['value']
@app.callback( # Select sub-category
Output('location-select2', 'value'),
[
Input('location-select2', 'options'),
#Input('county-select1', 'value'),
],
)
def update_output19(available_options):
return available_options[0]['value']
@app.callback( # Update available sub_categories
Output('county-select1', 'options'),
[
Input('location-select1', 'value'),
#Input('county-select1', 'value'),
],
)
def update_output13(v1):
counties_df = []
with open('DataUpdate/data/States_Counties.txt', 'rb') as csvfile:
counties_df = pd.read_csv(csvfile, sep='\t')
try:
counties_df.drop(['Unnamed: 0'], axis=1, inplace=True)
except:
pass
tdf = counties_df[counties_df['Province/State'] == v1]
cts = sorted(list(set(tdf['Admin2'].values.tolist())))
tdf = 0
l = 'Entire state or territory'
cts.insert(0, l)
return [{"label": i, "value": i} for i in cts]
@app.callback( # Update available sub_categories
Output('county-select2', 'options'),
[
Input('location-select2', 'value'),
#Input('county-select1', 'value'),
],
)
def update_output20(v1):
with open('DataUpdate/data/States_Counties.txt', 'rb') as csvfile:
counties_df = pd.read_csv(csvfile, sep='\t')
try:
counties_df.drop(['Unnamed: 0'], axis=1, inplace=True)
except:
pass
tdf = counties_df[counties_df['Province/State'] == v1]
cts = sorted(list(set(tdf['Admin2'].values.tolist())))
tdf = 0
l = 'Entire state or territory'
cts.insert(0, l)
return [{"label": i, "value": i} for i in cts]
@app.callback( # Update available sub_categories
Output('model-select1', 'options'),
[
Input('location-select1', 'value'),
Input('county-select1', 'value'),
],
)
def update_output14(loc1, loc2):
return [{"label": i, "value": i} for i in models]
@app.callback( # Update available sub_categories
Output('model-select2', 'options'),
[
Input('location-select2', 'value'),
Input('county-select2', 'value'),
],
)
def update_output17(loc1, loc2):
return [{"label": i, "value": i} for i in models]
@app.callback(
[Output('df1', 'children'),
Output("model_forecasts_plot1", "figure")],
[Input("location-select1", "value"),
Input("county-select1", "value"),
Input("model-select1", "value"),
#Input("add-forecast1", "n_clicks"),
Input("reset-btn1", "n_clicks"),
Input("date1", "date"),
],
)
def update_model_forecast1(loc, county, model, reset_click, startdate):
reset = False
# Find which one has been triggered
ctx = dash.callback_context
if ctx.triggered:
prop_id = ctx.triggered[0]["prop_id"].split(".")[0]
if prop_id == "reset-btn1":
reset = True
df_fits = app_fxns.generate_model_forecasts(loc, county, model, reset, startdate)
fig1 = app_fxns.generate_model_forecast_plot(df_fits, reset)
return df_fits, fig1
@app.callback(
Output("new_cases_plot1", "figure"),
[Input('df1', 'children'),
Input("location-select1", "value"),
Input("county-select1", "value"),
Input("reset-btn1", "n_clicks")
],
)
def update_model_forecast111(df, loc, county, reset_click):
reset = False
# Find which one has been triggered
ctx = dash.callback_context
if ctx.triggered:
prop_id = ctx.triggered[0]["prop_id"].split(".")[0]
if prop_id == "reset-btn1":
reset = True
fig = app_fxns.generate_plot_new_cases(df, loc, county, reset)
return fig
@app.callback(
Output('model_forecast_link', 'href'),
[Input('df1', 'children'),
Input("location-select1", "value"),
Input('county-select1', 'value'),
Input("reset-btn1", "n_clicks")],
)
def update_table_model_forecast1(df_fits, loc, cty, reset_click):
reset = False
# Find which one has been triggered
ctx = dash.callback_context
if ctx.triggered:
prop_id = ctx.triggered[0]["prop_id"].split(".")[0]
if prop_id == "reset-btn1":
reset = True
# Return to original hm(no colored annotation) by resetting
return app_fxns.generate_model_forecast_table(df_fits, reset)
@app.callback(
Output('df2', 'children'),
[Input('df1', 'children'),
Input("location-select1", "value"),
Input('county-select1', 'value'),
Input("model-select1", "value"),
Input("ICU beds1", "value"),
Input("nonICU beds1", "value"),
Input("visits1", "value"),
Input("admits1", "value"),
Input("percent ICU1", "value"),
Input("ICU LOS1", "value"),
Input("non-ICU LOS1", "value"),
Input("on vent1", "value"),
Input("time lag1", "value"),
Input("transfers1", "value"),
Input("percent transferICU1", "value"),
Input('mortality1', "value"),
Input("gloves1", "value"),
Input("gloves2", "value"),
Input("gloves3", "value"),
Input("mask1", "value"),
Input("mask2", "value"),
Input("gown1", "value"),
Input("mask3", "value"),
Input("shield1", "value"),
Input('resp1', "value"),
Input("reset-btn1", "n_clicks"),
Input("date1", "date"),
],
)
def update_patient_census(df1, loc, cty, model, icu_beds, nonicu_beds, per_loc, per_admit,