-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
3178 lines (2806 loc) · 124 KB
/
app.R
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
# Date: 2019/8/1
# Contributors:
# UI: Shengjin Li (prototype)
# Server: Yuxuan Wang (prototype)
# Visualizations: Ziyi Wang (prototype)
# Fall 2019 Coding Team: Ross DeVito, Jose Figueroa, Xinyu Gu, Taras Kaminsky, Lilian Ngweta,
# Jiangshan Lin, Farukh Saidmuratov, Christina Van Hal, Ziyi Wang, Hongrui Zhang
# Advisors: Kristin Bennett, John Erickson, Karan Bhanot
# The Rensselaer Institute for Data Exploration & Applications (IDEA)
source("Source.R")
deps <- list("topojson.min.js",
htmlDependency(name = "d3-scale-chromatic",
version = "1.3.3",
src = list(href = "https://d3js.org/"),
script = "d3-scale-chromatic.v1.min.js")
)
#-----------------
state.list <- state.abb
names(state.list) <- state.name
state.list <- append(state.list, "United States", after = 0)
# Cause list with Assault
# cause.list <- c("All Cause" = "All Cause", "Deaths by Assault"="Assault","Cancer Deaths"="Cancer","Cardiovascular Disease"="Cardiovascular","Deaths of Despair"="Despair")
# cause.definitions <- c("\"Deaths of Despair\" are deaths due to suicide, overdose, substance abuse and poisonings"="Despair",
# "\"Deaths by Assault\" are deaths caused by injuries inflicted by another person with intent to injure or kill, by any means"="Assault",
# "\"Cardiovascular Disease\" are deaths due to diseases of the circulatory systems such as heart disease and stroke"="Cardiovascular",
# "\"Cancer Deaths\" are deaths due to cancer and neoplasm"="Cancer")
# Cause list with Assault commented out
cause.list <- c("All Cause" = "All Cause","Cancer"="Cancer","Cardiovascular Disease"="Cardiovascular","Deaths of Despair"="Despair")
cause.definitions <- c("\"Deaths of Despair\" are deaths due to suicide, overdose, substance abuse and poisonings"="Despair",
"\"Cardiovascular Disease\" are deaths due to diseases of the circulatory systems such as heart disease and stroke"="Cardiovascular",
"\"Cancer\" refers to deaths due to cancer and neoplasm"="Cancer")
period.list <- c("2000-2002","2003-2005","2006-2008","2009-2011","2012-2014","2015-2017")
n.clusters.state = 3
n.clusters.nation = 6
jscode <- "shinyjs.nextpage = function(){$('.fp-next').click();}"
ui_list <- list()
ui_list[["Page1"]] <- fluidPage(
##################### CSS Imports #####################
useShinyjs(),
extendShinyjs(text = jscode, functions = c("nextpage")),
tags$head(includeCSS("custom_no_scroll.css")),
tags$head(includeCSS("jquery-ui.min.css")),
tags$head(includeCSS("fullpage.css")),
tags$head(includeCSS("geoattr.css")),
tags$head(
tags$script(src="jquery-3.4.1.min.js"),
tags$script("$.noConflict(true);")),
##################### NAV BAR #####################
tags$div(
class = "navbar",
tags$div(
class = "title",
tags$h1(
"MortalityMinder")
),
tags$div(
class = "input",
tags$h3(id = "input_text2", "State:"),
uiOutput("p1_state_selector"),
tags$h3(id = "input_text1", "Cause of Death:"),
uiOutput("p1_death_selector"),
uiOutput("p1_updater")
)
),
tags$div(
id = "fullpage",
tags$div(
class = "section s1",
##################### PAGE 1, NATIONWIDE ANALYSIS #####################
tags$div(
class = "slide",
tags$div(
class = "nav_bar_blank"
),
# Div tag functions as outter "shell" to pull from fullpage.css
# Each page is a row, of columns, of rows, etc.
fluidRow(
class = "page page1", # National Map Page
uiOutput("national_map"),
column(3,
class="page1_col page1_col1",
tags$div(
class = "page1_col1_heading",
htmlOutput("page1_main_header")
),
tags$h4("MortalityMinder analyzes trends of premature death in the United States which are caused by:\n"),
tags$ul(
tags$li("All Causes"),
tags$li("Cancer"),
tags$li("Deaths of Despair"),
tags$li("Cardiovascular Disease")
# tags$li(tags$h4("Assault Deaths"))
), # End List
tags$h4("MortalityMinder is an interactive presentation that examines county-level factors associated with midlife mortality trends.\n"),
HTML("<h4>Choose <b>State</b> and <b>Cause of Death</b> on the menu bar at the top of the page(and <b>Risk Factor</b> on Factor View page) to see how mortality rates in the selected state and the United States have changed from 2000 to 2017.</h4>"),
tags$br(),
tags$img(
class="IDEA_Logo_Wrapper2",
width = "80%",
src="RPIlogo.png",
alt = "Institute of Data Exploration and Applications")
), # End Column 1
tags$div(
class = "vl"
),
column(8,
fluidRow(
class = "page1_col page1_col2_top",
tags$div(
class = "page1_title",
uiOutput("textNationalTitle"),
uiOutput("textMortFactsClosing")
)
), # End of inner FluidRow (Column 2 top)
fluidRow(class="page1_col page1_col2_middle",
fluidRow(
tags$ul(
class = "ul_period",
tags$button(
id = "first_period",
class = "period_text",
"2000-02"
),
tags$button(
id = "second_period",
class = "period_text",
"2003-05"
),
tags$button(
id = "third_period",
class = "period_text",
"2006-08"
),
tags$button(
id = "forth_period",
class = "period_text",
"2009-11"
),
tags$button(
id = "fifth_period",
class = "period_text",
"2012-14"
),
tags$button(
id = "sixth_period",
class = "period_text",
style= "background-color: #565254; color: #f7f7f7;",
"2015-17"
)
) # End List of buttons
), # End Button Functionality
fluidRow(
class="page1_col2_graphics_row",
column(6,
class = "page1_col page1_col2_middle_left",
# tags$h3("National Plot Title"),
tags$div(class = "page1_title",
uiOutput("textNationwideTitle")
),
tags$div(class="NationalMapContainer",
style="position:relative;width: 100%;left: 0;",
tags$img(
id = "national_map_new",
class = "landing_page_map",
src = "Despair/1.png",
alt = "US National map plotting deaths of despair at the county level."
)
) # End of Image DIV container
), # End of Middle inner Column
column(6,
class = "page1_col page1_col2_middle_right",
tags$div(class = "page1_title",
uiOutput("textInfographicTitle")
),
tags$div(class = "nation_state_infographic",
plotOutput("nation_state_infographic")
)
)
)
)
, # End of inner Fluid Row (Column 2 Middle)
fluidRow(
class = "page1_col page1_col2_bottom",
uiOutput("textMortFactsNew")
) # Close inner FluidRow (Column 2 Bottom)
) #Close Column 2
) #Close Outter Row (National Map Page)
) # Close div tag "slide"
)
)
)
ui_list[["Page2"]] <- fluidPage(
##################### CSS Imports #####################
useShinyjs(),
extendShinyjs(text = jscode, functions = c("nextpage")),
tags$head(includeCSS("custom_no_scroll.css")),
tags$head(includeCSS("jquery-ui.min.css")),
tags$head(includeCSS("fullpage.css")),
tags$head(includeCSS("geoattr.css")),
tags$head(
tags$script(src="jquery-3.4.1.min.js"),
tags$script("$.noConflict(true);")),
##################### NAV BAR #####################
tags$div(
class = "navbar",
tags$div(
class = "title",
tags$h1(
"MortalityMinder")
),
tags$div(
class = "input",
tags$h3(id = "input_text2", "State:"),
uiOutput("p2_state_selector"),
tags$h3(id = "input_text1", "Cause of Death:"),
uiOutput("p2_death_selector"),
uiOutput("p2_updater"),
tags$script(src = "jquery-ui.min.js"),
tags$script(src = "fullpage.js"),
tags$script(src = "jquery.ba-outside-events.js"),
includeScript(path = "myscript.js")
),
##################### PAGE 2, INDIVIDUAL STATE ANALYSIS #####################
tags$div(
class = "slide",
tags$div(
class = "nav_bar_blank"
),
fluidRow(
class = "page page2",
column(7,
class="page2_col page2_col1",
fluidRow(
class="page2_col page2_col1_top",
column(4,
class = "page2_col page2_col1_top_left",
tags$div(
class = "page2_col1_heading",
htmlOutput("page2_main_header")
),
uiOutput("textDescription")
), # End of inner Column (Column 1 Top Left)
column(8,
class = "page2_col page2_col1_top_right",
tags$div(
class="page2_col1_top_right_title",
uiOutput("textMortRates")
), # End of title div container
radioButtons("year_selector",
#label = "Click on time period to select state map for that period",
label = NULL,
selected = "2015-2017",
choiceNames = c("2000-02", "2003-05", "2006-08", "2009-11", "2012-14", "2015-17"),
choiceValues = c("2000-2002", "2003-2005", "2006-2008", "2009-2011", "2012-2014", "2015-2017"),
inline = TRUE),
leafletOutput("geo_mort_change2",width="82%",height="75%")
) # End of inner Column (Column 1 top right)
), # End of inner FluidRow (Column1 Top)
tags$div(
class = "hr"
),
fluidRow(
class = "page2_col page2_col1_bot",
column(5,
class = "page2_col page2_col1_bot_left",
tags$div(
class="page2_col1_bot_left_title",
uiOutput("textClusterGeo")
), # End of title div container
leafletOutput("geo_cluster_kmean",width="82%",height="75%")
), # End of inner Column (Bottom Left)
column(5,
class = "page2_col page2_col1_bot_right",
tags$div(
class="page2_col1_bot_right_title",
uiOutput("textDeathTrends")
), # End of title div container
plotOutput("mort_line",width="100%",height="70%")
) # End of inner Column (Bottom Right)
) #End of inner fluidRow (Column 1 Bottom)
), # End of Column 1
column(3,
class = "page2_col page2_col2",
tags$div(
class = "page2_col2_title",
uiOutput("textDeterminants")
), # End of title container
tags$div(
class = "page2_col2_plot",
plotOutput("page1.bar.cor1",width="100%",height="100%",
# hover = hoverOpts("plot_hover", delay = 100, delayType = "debounce"),
hover = hoverOpts("plot_hover"),
click = clickOpts("page1_bar_plot_click")),
uiOutput("hover_info")
) # End of plot div container
) # End of Column 2
)# End of FluidRow (Page1, State Analysis)
), # End of slide div tag
tags$script(src = "jquery-ui.min.js"),
tags$script(src = "fullpage.js"),
tags$script(src = "jquery.ba-outside-events.js"),
includeScript(path = "myscript.js")
)
)
ui_list[["Page3"]] <- fluidPage(
##################### CSS Imports #####################
useShinyjs(),
extendShinyjs(text = jscode, functions = c("nextpage")),
tags$head(includeCSS("custom_no_scroll.css")),
tags$head(includeCSS("jquery-ui.min.css")),
tags$head(includeCSS("fullpage.css")),
tags$head(includeCSS("geoattr.css")),
tags$head(
tags$script(src="jquery-3.4.1.min.js"),
tags$script("$.noConflict(true);")),
##################### NAV BAR #####################
tags$div(
class = "navbar",
tags$div(
class = "title",
tags$h1(
"MortalityMinder")
),
tags$div(
class = "input",
tags$h3(id = "input_text2", "State:"),
uiOutput("p3_state_selector"),
tags$h3(id = "input_text1", "Cause of Death:"),
uiOutput("p3_death_selector"),
uiOutput("p3_updater"),
tags$script(src = "jquery-ui.min.js"),
tags$script(src = "fullpage.js"),
tags$script(src = "jquery.ba-outside-events.js"),
includeScript(path = "myscript.js")
),
##################### PAGE 3, INDIVIDUAL DETERMINANT ANALYSIS #####################
tags$div(
class = "slide",
tags$div(
class = "nav_bar_blank"
),
fluidRow(
class = "page page3",
column(4,
class = "page3_col page3_col3",
fluidRow(
class = "page3_col3_top",
tags$div(
class = "page3_col1_heading",
htmlOutput("page3_main_header")
),
tags$div(
tags$div(
class = "prompt_text",
"Select a factor:"
),
pickerInput(
inputId = "determinant_choice",
label = "Selected Determinant: ",
choices = str_sort(chr.namemap.2019[intersect(colnames(chr.data.2019), rownames(chr.namemap.2019)),]),
selected = "Socio-Economic",
width = "100%",
inline = TRUE,
options = list(
`live-search` = TRUE,
"dropup-auto" = TRUE
) # End of Options
) # End of pickerInput
), # End of pickerInput container
tags$br(),
tags$h4(htmlOutput("determinant_text")),
tags$h5(uiOutput("determinant_link")),
tags$h5(htmlOutput("determinant_original_source")),
tags$h5(htmlOutput("determinant_corr")),
tags$h5(htmlOutput("determinant_dir"))
),# End of Column 3 top
tags$br(),
fluidRow(
class = "page3_col3_bot",
tags$div(
tags$div(
class = "prompt_text",
uiOutput("textCountyPrompt")
),
uiOutput("county_selector")
), # End of pickerInput container
leafletOutput("determinants_plot5", width="82%",height="75%"),
tags$div(
class="data_source_footnote",
HTML("<h6 style='text-align: right;'>Mortality Data: CDC Wonder Detailed Mortality<br>Feature Data: County Health Rankings<br>Analysis: The Rensselaer IDEA</h6>")
),
fluidRow(
class = "page3_col3_county_desc",
uiOutput("county_desc")
)
) # End of inner Column 3 bottom
), # End Column 1
tags$div(
class = "vl"
),
column(4,
class = "page3_col page3_col2",
fluidRow(
class = "page3_col2_top",
uiOutput("textBoxplotTitle"),
plotOutput("determinants_plot2",height="70%")
), #End of Column 2 Top
#tags$div(class = "hr"),
fluidRow(
class = "page3_col2_bot",
style = "position: relative",
uiOutput("textScatterplotTitle"),
uiOutput("determinants_plot3_county_name"),
plotOutput("determinants_plot3",height="80%",
click = clickOpts("determinants_plot3_click"), hover = hoverOpts("determinants_plot3_hover"))
) # End of Column 2 Bottom
), # End of Column 2
tags$div(
class = "vl"
),
column(4,
class = "page3_col page3_col1",
tags$div(
class = "col1_title",
uiOutput("textDeterminants2")
), # End title div container
plotOutput("determinants_plot1", height = "95%", width = "100%",
click = clickOpts("page2_bar_plot_click"))
)
# End of Column 3
) # End of Fluid Row
), # End of Page 3
tags$script(src = "jquery-ui.min.js"),
tags$script(src = "fullpage.js"),
tags$script(src = "jquery.ba-outside-events.js"),
includeScript(path = "myscript.js")
)
)
ui_list[["Page4"]] <- fluidPage(
##################### CSS Imports #####################
useShinyjs(),
extendShinyjs(text = jscode, functions = c("nextpage")),
tags$head(includeCSS("custom_no_scroll.css")),
tags$head(includeCSS("jquery-ui.min.css")),
tags$head(includeCSS("fullpage.css")),
tags$head(includeCSS("geoattr.css")),
tags$head(
tags$script(src="jquery-3.4.1.min.js"),
tags$script("$.noConflict(true);")),
##################### NAV BAR #####################
tags$div(
class = "navbar",
tags$div(
class = "title",
tags$h1(
"MortalityMinder")
),
tags$div(
class = "input",
tags$h3(id = "input_text2", "State:"),
uiOutput("p4_state_selector"),
tags$h3(id = "input_text1", "Cause of Death:"),
uiOutput("p4_death_selector"),
uiOutput("p4_updater"),
tags$script(src = "jquery-ui.min.js"),
tags$script(src = "fullpage.js"),
tags$script(src = "jquery.ba-outside-events.js"),
includeScript(path = "myscript.js")
),
##################### PAGE 4, ABOUT PAGE #####################
tags$div(
class = "slide",
tags$div(
class = "nav_bar_blank"
),
fluidRow(
class = "page page4",
column(4, tags$h4(paste("About Mortality Minder"),align="center"),
fluidRow(
column(11,
HTML("<h5>The goal of MortalityMinder (MM) is to enable healthcare researchers, providers,
payers, and policy makers to gain actionable insights into how, where,
and why midlife mortality rates are rising in the United States (US).
</h5>"),
tags$ul(
tags$li(HTML("Explores mortality trends for midlife adults ages 25-64 across the United
States from 2000 to 2017 using data from <a href=\"https://wonder.cdc.gov/mcd.html\"
target=\"_blank\">CDC WONDER</a>, the definitive source of US mortality data.")
),
tags$li(
HTML("Identifies social and economic factors associated with increased mortality trends at the
county-level for each state and the nation obtained from <a href=\"https://www.countyhealthrankings.org/\"
target=\"_blank\">County Health Rankings (CHR)</a>, an aggregate of county-level data from 20 sources
curated by the Robert Wood Johnson Foundation.")
),
tags$li("Addresses factors including health behaviors, clinical care, education, employment, social supports,
community safety and physical environment domains."),
tags$li(
"Interactively visualizes potential determinants and their impact on mortality trends."
),
tags$li(
"Investigates deaths due to All Causes, Cancer Deaths, Cardiovascular Deaths, Deaths of Despair (suicide, self harm and overdose)."
),
tags$li(HTML(
"Publicly-accessible, freely available, easily maintained, and readily extensible
<a href='https://github.com/TheRensselaerIDEA/MortalityMinder/' target=_blank>open source</a> web tool.")
)
),
HTML("<h5>Limitation: Associated factors are correlated to midlife mortality rates. Further investigation is needed to see if they actually cause changes in mortality rate.</h5>")
),
column(11, tags$h4("DOWNLOAD SOURCE DATA",align="center"),
fluidRow(downloadButton("downloadCDCData", "Mortality Data", class = "dbutton")), ##tags$br(),
fluidRow(downloadButton("downloadCHRData", "Factor Data", class = "dbutton")), ##tags$br(),
fluidRow(downloadButton("downloadFactorDesc", "Factor Descriptions", class = "dbutton")), ##tags$br(),
tags$h4("DOWNLOAD CURRENT RESULTS",align="center"),
fluidRow(downloadButton("downloadClusters", "Current State Clusters", class = "dbutton")), ##tags$br(),
fluidRow(downloadButton("downloadClusterTime", "Current State Clusters Through Time", class = "dbutton")), ##tags$br(),
fluidRow(downloadButton("downloadCorr", "Current Factor Correlations", class = "dbutton"))
),
column(11,
tags$img(
class="IDEA_Logo_Wrapper3",
src="no_mobile.png",
alt = "Do not use with mobile devices"),
tags$h6("MortalityMinder has been optimized for laptop and large-screen use. Use with mobile devices is not recommended.")
)
) # Close row
), #close column
column(4, tags$h4("INNOVATION",align="center"), offset=1,
fluidRow(
column(11, tags$h5("MortalityMinder (MM) dramatically illustrates midlife mortality rate increases reported in (Wolf and Schoomaker,
JAMA 2019), while providing greater insight into community-level variations and their associated
factors to help determine remedies."),
HTML("<h5>Using authoritative data from the CDC and other sources, MM is designed to help health policy decision makers in the
public and private sectors identify and address unmet healthcare needs, healthcare costs, and healthcare utilization.</h5>"),
HTML("<h5>Innovative analysis divides counties into <b>risk groups</b> for visualization and correlation analysis using K-Means clustering and Kendall correlation.</h5>"),
HTML("<h5>For each State and Cause of Death, MM dynamically creates three analysis and visualization infographics:</h5>"),
tags$ul(
tags$li(HTML("<b>National View</b> reveals midlife mortality rates through time and compares state and national trends.")),
tags$li(HTML("<b>State View</b> categorizes counties into risk groups based on their midlife mortality rates over time.
The app determines correlations of factors to risk groups and visualizes the most significant protective
and destructive factors. ")),
tags$li(HTML("<b>Factor View</b> enables users to explore individual factors including their relation to the selected cause at
a county level for each state and the distribution of those factors within each state.")),
tags$li(HTML("Selecting 'United States' for <b>State</b> initiates nationwide analysis."))
)),
column(11, tags$h4("INSIGHTS",align="center"),
HTML("<h5>MortalityMinder provides a compelling and engaging tool to investigate the social and economic determinants of mortality. MM:</h5>"),
tags$ul(
tags$li("Documents the disturbing rise in midlife Deaths of Despair due to suicide, overdose, and self-harm and other
national/regional increases in midlife mortality rates due to All Causes, Cancer, and Cardiovascular Disease."),
tags$li("Highlights potential social determinants through statistical analysis of factors associated with disparities
in regional trends in midlife mortality rates."),
tags$li("Provides county-level confirmation of trends and hypothesized causes."),
tags$li("Yields insights that can be used to create region-specific interventions and best practices to meet unmet healthcare needs."),
tags$li("Enables rigorous analysis of potential determinants of health by local, state, and national healthcare
organizations to support development of programs, policies, and procedures to improve longevity. ")
) # End of list
)
),
fluidRow(class="IDEA_Logo_Wrapper",
tags$img(
class="Idea_Logo",
src="IDEA_logo_500.png",
width="100%",
style="bottom: 0; left: 0;",
alt = "Institute of Data Exploration and Applications"
)
)
), # Close column
column(4,
column(11, tags$h4("IMPLEMENTATION AND DEPLOYMENT",align="center"),
HTML("<h5>MortalityMinder is an open-source R project freely available with full documentation via a
<a href='https://github.com/TheRensselaerIDEA/MortalityMinder/', target=_blank>GitHub repository</a>.</h5>"),
tags$ul(
tags$li("R was chosen for its powerful environment for statistical computing and graphics using standard packages. "),
tags$li(HTML("MM utilizes the <a href='https://shiny.rstudio.com/' target='_blank'>R Shiny</a> and
<a href='https://github.com/alvarotrigo/fullPage.js' target='_blank'>FullPage Javascript</a>
frameworks for web interactivity.")),
tags$li("Source data preparation is documented on the GitHub Wiki. Data Loader scripts enable new data sources
and preparations to be easily incorporated. Data may be downloaded under 'DOWNLOAD SOURCE DATA'."),
tags$li("Missing county mortality rates are imputed using state-wide rates and Amelia R Package."),
tags$li("MM can be run from the public web locations or installed locally."),
tags$li("Code is easily customized, extended, and maintained. The app continuously evolves in an agile framework
to incorporate user feedback and introductions of new data streams, analyses, visualization, and health
care problems."),
tags$li("App design based on formal usability study of 20+ users and recommendations from our advisory board of
healthcare and design professionals."),
tags$li("The innovative visualizations and analytics in MortalityMinder can be adapted into other applications
or formats by using the provided code and data.")
)
),
column(11, tags$h4("ACKNOWLEDGEMENTS", align = "center"),
tags$h5("MortalityMinder was created by undergraduate and graduate students in the Health Analytics Challenge Lab at Rensselaer Polytechnic Institute with generous support from the United Health Foundation and the Rensselaer Institute for Data Exploration and Applications (IDEA). MortalityMinder was directed by Kristin P. Bennett and John S. Erickson."),
tags$h5("The MortalityMinder Team would like to thank our advisory board, including Ms. Anne Yau, United Health Foundation; Dr. Dan Fabius, Continuum Health; Ms. Melissa Kamal, New York State Department of Health; and Dr. Tom White, Capital District Physicians' Health Plan (CDPHP).")
),
column(11, tags$h4("LINKS", align = "center"),
HTML("<h5><a href='https://github.com/TheRensselaerIDEA/MortalityMinder/' target=_blank>MortalityMinder GitHub Repository (public)</a><br>
<a href='https://github.com/TheRensselaerIDEA/MortalityMinder/wiki' target=_blank>MortalityMinder GitHub Wiki (public)</a><br>
<a href='https://bit.ly/mortalityminder_video_final' target=_blank>MortalityMinder Video</a><br>
<a href='http://bit.ly/mortalityminder_slides' target=_blank>MortalityMinder Overview Slides</a><br><br>
Please send questions and comments about MortalityMinder to: <a href='mailto:[email protected]' target=_blank>[email protected]</a><br>
Suggest improvements and report bugs on <a href='https://github.com/TheRensselaerIDEA/MortalityMinder/issues' target=_blank>GitHub</a></h5>")
)
)
# Close inner fluidRow
)
) # Close outter fluidRow
), # Close Page 4
tags$script(src = "jquery-ui.min.js"),
tags$script(src = "fullpage.js"),
tags$script(src = "jquery.ba-outside-events.js"),
includeScript(path = "myscript.js")
)
draw_border <- function(plot.name, border){
proxy <- leafletProxy(plot.name)
# remove any previously highlighted polygon
proxy %>% clearGroup("highlighted_polygon")
#add a slightly thicker red polygon on top of the selected one
proxy %>% addPolylines(stroke = TRUE,
weight = 4,
color="black",
data = border,
group="highlighted_polygon",
dashArray = "4 2 4")
}
highlight_county <- function(event){
county_name <- sub(event$id, pattern = " [[:alpha:]]*$", replacement = "")
county_indices <- which(state_map@data$NAME %in% c(county_name))
if (length(county_indices) == 0){
for (current_polygons in state_map@polygons){
for (current_polygon in current_polygons@Polygons){
current_coords <- current_polygon@coords
if (sp::point.in.polygon(c(event$lng), c(event$lat), current_coords[,1], current_coords[,2])){
assign("county_polygon", current_polygons, envir = .GlobalEnv)
break
}
}
}
}else if (length(county_indices) == 1){
assign("county_polygon", state_map@polygons[[county_indices[[1]]]], envir = .GlobalEnv)
} else {
for (index in county_indices){
current_polygon <- state_map@polygons[[index]]
current_coords <- current_polygon@Polygons[[1]]@coords
if (sp::point.in.polygon(c(event$lng), c(event$lat), current_coords[,1], current_coords[,2])){
assign("county_polygon", current_polygon, envir = .GlobalEnv)
break
}
}
}
draw_border("geo_cluster_kmean", county_polygon)
draw_border("geo_mort_change2", county_polygon)
draw_border("determinants_plot5", county_polygon)
}
generate_text <- function(name, diff_pct){
change_text <- paste0("The mortality rate \nhas ")
if (diff_pct > 0) {
change_text <- paste0(change_text, "increased ")
}
else {
change_text <- paste0(change_text, "decreased ")
}
change_text <- paste0(change_text, "in \n", name, " by ", abs(round(diff_pct,1)), "%")
change_text
}
generate_label_data <- function(state_data, nation_data, state_begin, state_end, nation_begin, nation_end, state_x, state_y, nation_x, nation_y, sc){
state_data <- state_data %>%
mutate(label = "") %>%
rename(x = period)
nation_data <- nation_data %>%
mutate(label = "") %>%
rename(x = period)
rbind(generate_label_data_single(state_data, sc, state_begin, state_end, state_x, state_y),
generate_label_data_single(nation_data, "United States", nation_begin, nation_end, nation_x, nation_y))
}
generate_label_data_single <- function(data, name, begin, end, label_x, label_y){
label_data = data.frame(data)
label_data$x[label_data$x=="2000-2002"] <- 1
label_data$x[label_data$x=="2003-2005"] <- 2
label_data$x[label_data$x=="2006-2008"] <- 3
label_data$x[label_data$x=="2009-2011"] <- 4
label_data$x[label_data$x=="2012-2014"] <- 5
label_data$x[label_data$x=="2015-2017"] <- 6
label_data$x <- as.numeric(as.character(label_data$x))
n <- 10
d_max <- 0
for (i in 1:5){
r1 <- label_data[label_data$x==i,]
r2 <- label_data[label_data$x==i+1,]
for (j in 1:n-1){
for (d in 0:d_max){
label_data <- rbind(label_data, data.frame("x" = i+j/n,
"death_rate" = r2$death_rate*j/n+r1$death_rate*(n-j)/n-d,
"label" = c(""),
"group" = c(name)))
label_data <- rbind(label_data, data.frame("x" = i+j/n,
"death_rate" = r2$death_rate*j/n+r1$death_rate*(n-j)/n+d,
"label" = c(""),
"group" = c(name)))
}
}
}
mort_diff <- (end - begin) / begin * 100
mort_text <- generate_text(name, mort_diff)
rbind(label_data,
data.frame("x" = label_x,
"death_rate" = label_y,
"label" = mort_text,
"group" = name))
}
draw_reference <- function(line_plot, l_start, l_end, r_start, r_end){
line_plot <- draw_reference_single(line_plot, l_start, l_end, 1, l_end)
draw_reference_single(line_plot, r_start, r_end, 6, r_start)
}
draw_reference_single <- function(line_plot, start, end, x, y){
line_plot +
geom_segment(aes(x='2000-2002', xend='2015-2017', y=y, yend=y),
color = '#565254', linetype=2) +
geom_segment(aes(x=x, xend=x, y=start, yend=end),
color = '#565254', linetype=1, arrow = arrow(length=unit(0.4,"cm")))
}
add_reference_point <- function(label_data, l_start, l_end, r_start, r_end){
label_data <- add_reference_point_single(label_data, l_start, l_end, 1, "United States")
add_reference_point_single(label_data, r_start, r_end, 6, "United States")
}
add_reference_point_single <- function(label_data, start, end, x, name){
rbind(label_data, data.frame("x" = rep(c(x), times = 6),
"death_rate" = seq(start, end, length.out = 6),
"label" = rep(c(""), times = 6),
"group" = rep(c(name), times = 6)))
}
# ##################### Server Code #####################
serv_calc <- list()
# This calc initializes the navbar selections immediately. It is auto-
# invalidated when the app runs. It updates state_choice and death_cause
# which calc[[3]] uses to update all the pickers. After that, it self
# destructs and never runs again
serv_calc[[1]] <- function(calc, session) {
# if(!exists("calc$state_choice")) {
calc$onInit <- observe({
invalidateLater(0)
calc$state_choice <- "OH"
calc$death_cause <- "Despair"
calc$onInit$destroy()
})
}
# The update button changes state_choice and death_cause, which invalidates
# calc[[3]]. choice and cause can only be updated by pressing the button.
# Previous versions used the dropdown selection as the method for change
# but this ended up causing issues
serv_calc[[2]] <- function(calc, session) {
observeEvent(calc$p1_push, {
calc$state_choice <- calc$p1_state_choice
calc$death_cause <- calc$p1_death_cause
})
observeEvent(calc$p2_push, {
calc$state_choice <- calc$p2_state_choice
calc$death_cause <- calc$p2_death_cause
})
observeEvent(calc$p3_push, {
calc$state_choice <- calc$p3_state_choice
calc$death_cause <- calc$p3_death_cause
})
observeEvent(calc$p4_push, {
calc$state_choice <- calc$p4_state_choice
calc$death_cause <- calc$p4_death_cause
})
}
# When state_choice or death_cause are changed, this calc updates
# all the pickers across the open pages
serv_calc[[3]] <- function(calc, session) {
observeEvent(calc$state_choice, {
updatePickerInput(session, "p1_state_choice", selected = calc$state_choice)
updatePickerInput(session, "p2_state_choice", selected = calc$state_choice)
updatePickerInput(session, "p3_state_choice", selected = calc$state_choice)
updatePickerInput(session, "p4_state_choice", selected = calc$state_choice)
})
observeEvent(calc$death_cause, {
updatePickerInput(session, "p1_death_cause", selected = calc$death_cause)
updatePickerInput(session, "p2_death_cause", selected = calc$death_cause)
updatePickerInput(session, "p3_death_cause", selected = calc$death_cause)
updatePickerInput(session, "p4_death_cause", selected = calc$death_cause)
})
}
serv_calc[[4]] <- function(calc, session) {}
#Extracting the national mean
serv_calc[[5]] <- function(calc, session) {
calc$determinant.url <- reactive({
return(as.character(
SocialDeterminants[SocialDeterminants$Name == calc$determinant_choice,]$"URL"))
})
}
serv_calc[[6]] <- function(calc, session) {
calc$determinant.source <- reactive({
return(as.character(
SocialDeterminants[SocialDeterminants$Name == calc$determinant_choice,]$"Source"))
})
calc$determinant.source_url <- reactive({
return(as.character(
SocialDeterminants[SocialDeterminants$Name == calc$determinant_choice,]$"Source_url"))
})
}
serv_calc[[7]] <- function(calc, session) {
calc$county_choice <- reactiveVal()
}
serv_calc[[8]] <- function(calc, session) {
calc$mort.rate <- reactive({
calc$county_choice(NULL)
assign("county_polygon", NULL, envir = .GlobalEnv)
assign("page1_period_choice", 6, envir = .GlobalEnv)
if(calc$state_choice == "United States"){
cdc.data %>% dplyr::filter(
death_cause == calc$death_cause,
#state_abbr == calc$state_choice,
period == "2015-2017"
) %>%
dplyr::mutate(
# death_rate = death_num / population * 10^5
#death_rate = cut(death_rate, bin.geo.mort("Despair"))
) %>%
dplyr::select(county_fips, death_rate)
}else {
assign("state_map", readRDS(paste("../shape_files/", calc$state_choice, ".Rds", sep = "")), envir = .GlobalEnv)
cdc.data %>% dplyr::filter(
death_cause == calc$death_cause,
state_abbr == calc$state_choice,
period == "2015-2017"
) %>%
dplyr::mutate(
# death_rate = death_num / population * 10^5
#death_rate = cut(death_rate, bin.geo.mort("Despair"))
) %>%
dplyr::select(county_fips, death_rate)
}
})
}
# get unfiltered kendal cors
serv_calc[[9]] <- function(calc, session) {
calc$kendall.cor <- reactive({
calc$kendall.cor.new <- calc$mort.rate() %>%
dplyr::mutate(VAR = death_rate) %>%
kendall.func(chr.data.2019) %>%
dplyr::mutate(
DIR = dplyr::if_else(
kendall_cor <= 0,
"Protective",
"Destructive"
),
chr_code = chr.namemap.2019[chr_code, 1]
) %>% na.omit()
})
}
# #Extracting the national mean
serv_calc[[10]] <- function(calc, session) {
calc$national.mean <- reactive({
switch(calc$death_cause,
"Despair" = {
death_rate <- c(28.929453, 33.665595, 37.821445, 40.081486, 43.900063, 55.084642)
},
"Assault" = {
death_rate <- c(6.750937, 6.729051, 6.687417, 5.934990, 5.915201, 6.999898)
},
"Cancer" = {
death_rate <- c(107.637100, 107.638200, 106.628310, 106.949100, 105.219690, 101.169700)
},
"Cardiovascular" = {
death_rate <- c(96.830591, 95.807343, 92.915303, 90.702418, 91.232679, 93.598232)
},
"All Cause" = {
death_rate <- c(366.07178, 373.10366, 373.65807, 373.40143, 379.60383, 395.93077)
})
nation.dataframe <- data.frame(
period = c("2000-2002", "2003-2005", "2006-2008", "2009-2011", "2012-2014", "2015-2017"),
cluster = rep("National", 6),
death_rate,
count = rep(NA, 6))
})
}
serv_calc[[11]] <- function(calc, session) {
calc$mort.rate.original <- reactive({
calc$county_choice(NULL)
assign("county_polygon", NULL, envir = .GlobalEnv)
assign("page1_period_choice", 6, envir = .GlobalEnv)
if(calc$state_choice == "United States"){
cdc.unimputed.data %>% dplyr::filter(
death_cause == calc$death_cause,
#state_abbr == calc$state_choice,
period == "2015-2017"
) %>%
dplyr::mutate(
# death_rate = death_num / population * 10^5
#death_rate = cut(death_rate, bin.geo.mort("Despair"))
) %>%
dplyr::select(county_fips, death_rate)
}else {
assign("state_map", readRDS(paste("../shape_files/", calc$state_choice, ".Rds", sep = "")), envir = .GlobalEnv)
cdc.unimputed.data %>% dplyr::filter(