-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.R
3696 lines (3036 loc) · 132 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
# EXTERNAL LIBRARIES
library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(dashboardthemes)
library(leaflet)
library(rgdal)
library(sf)
library(lubridate)
library(grDevices)
library(tidyverse)
library(classInt)
library(plotly)
library(data.table)
library(raster)
library(scales)
library(zoo)
library(ggthemes)
library(viridis)
library(prompter)
library(bigrquery)
library(gargle)
library(readr)
# FUNCTIONS FOR APP USE
source("DashFunctions.R")
##### DATA LOADING START #####
#### HISTORIC RASTERS
master.raster <- stack("Data/Master_Raster.grd")
monthly.raster <- stack("Data/EPA_Monthly.grd")
faa.mon.raster <- stack("Data/FAA_Monthly.grd")
#### HISTORIC SENSOR READINGS
epa.quarterly <- st_read("Data/EPA_Quarterly.geojson")
faa.quarterly <- st_read("Data/FAA_Quarterly.geojson")
epa.monthly <- st_read("Data/EPA_Monthly.geojson")
faa.monthly <- st_read("Data/FAA_Monthly.geojson")
#### COUNTY LEVEL DATA
large.area <- st_read("Data/LargeAreaCounties")
large.area$COUNTYNAME <- as.character(large.area$COUNTYNAME)
county.avgs <- read.csv("Data/county_averages_monthly.csv")
county.avgs$Name <- as.character(county.avgs$Name)
county.avgs$Name[16] = "Lake, WI"
var.avgs <- colMeans(county.avgs[,4:ncol(county.avgs)], na.rm = T)
#### MAP DATA
chi.map <- st_read("Data/Chicago")
chi.admin.map<- st_read("Data/ZipcodeBoundary")
chi.boundary<- st_union(chi.admin.map)
#### Variable Descriptions
descriptions <- read.csv("Data/Description.csv", stringsAsFactors = F)
#### HEALTH EXPLORER DATA
#### BigQuery Setup
# json_string = Sys.getenv("BQ_key")
# auth_email = Sys.getenv("BQ_user")
# bq_auth(email = auth_email,
# path = json_string)
# # project set up
# project <- "open-airq-bigquery" # replace this with your project ID
# sql_aqi <- "SELECT * FROM Scraped_Data.AQI"
# sql_pm25 <- "SELECT * FROM Scraped_Data.PM25"
# sql_pm25_means <- "SELECT * FROM Scraped_Data.PM25_means"
# sql_covid_raw <- "SELECT * FROM Scraped_Data.CovidWeekly"
# sql_covid_means <- "SELECT * FROM Scraped_Data.Covid_means"
# options(
# gargle_oauth_email = auth_email
# )
# # read in existing data
# pm25 <- bq_project_query(project, sql_pm25) %>%
# bq_table_download() %>%
# mutate(across(contains("PM25"), as.numeric)) %>%
# dplyr::select(Site_ID, COUNTY, latitude, longitude,
# name, everything()) %>%
# rename(Site.ID = Site_ID)
#
# pm25.means <- bq_project_query(project, sql_pm25_means) %>%
# bq_table_download()
#
# aqi <- bq_project_query(project, sql_aqi) %>%
# bq_table_download() %>%
# mutate(across(contains("AQI"), as.numeric)) %>%
# dplyr::select(Site_ID, COUNTY, latitude, longitude,
# name, everything()) %>%
# rename(Site.ID = Site_ID)
#
# covid.raw <- bq_project_query(project, sql_covid_raw) %>%
# bq_table_download() %>%
# mutate(across(contains("COVID"), as.numeric))
#
# covid.means <- bq_project_query(project, sql_covid_means) %>%
# bq_table_download() %>%
# column_to_rownames(var="time")
pm25<- read.csv("Data/PM25_Weekly/pm25.csv")
pm25.means<- read.csv("Data/PM25_Weekly/pm25_means.csv")
week.idx<- read.csv("Data/Week_Index.csv")$x
pm25.trace<- read.csv("Data/PM25_Weekly/pm25_trace.csv")$x
aqi<- read.csv("Data/PM25_Weekly/aqi.csv")
aqi.trace<- rev(read.csv("Data/PM25_Weekly/aqi_means.csv")[, -1])
covid.raw<- read.csv("Data/COVID/CovidWeekly.csv")
covid.means<- read.csv("Data/COVID/covid_means.csv", row.names=1)
covid.trace<- rev(covid.means[, -1])
asthma.raw<- read.csv("Data/COVID/Asthma2017.csv")
covid<- st_read("Data/COVID/covid.geojson")
asthma<- st_read("Data/COVID/asthma.geojson")
trees.all <- st_read("Data/Tract")
trees.var <- c("geoid", "svi_pecent", "trees_crow", "logtraf",
"urban_floo", "heatisl","nn_q3_pm2_", "asthma_5yr",
"hardship")
trees <- trees.all[,trees.var]
cdph.permits <- st_read("Data/CDPH_Permits")
#NN Data Loading
nn.raster <- stack("Data/NN/nn_21_base.grd")
nn.spatial <- stack("Data/NN/nn_21_spatialcv.grd")
nn.out <- stack("Data/NN/nn_21_outlier.grd")
nn.names <- read.csv("Data/NN_Raster_Names_New.csv")
names(nn.raster) <- nn.names$nn_names
names(nn.spatial) <- nn.names$nn_names
names(nn.out) <- nn.names$nn_names
##### DATA LOADING END #####
##### VARIABLE START #####
mapheight = "60vh"
# start_date<- strptime(names(covid)[ncol(covid) - 1], "COVID_Week_%Y%m%d")
end_date<- min(
strptime(names(covid)[6], "COVID_Week_%Y%m%d") + weeks(1),
today() - days(2)) # in case data update timing changes, prevents crashing
start_date<- end_date - weeks(12)
covid_na<- format(end_date, "COVID_Week_%Y%m%d")
covid[covid_na]<- NA
daterange<- paste("From", end_date - days(6), "to", end_date, sep = " ")
##### COLOR BREAKS #####
pm25.bins <- classIntervals(na.omit(unlist(pm25[,7:ncol(pm25)])), 5, style="fisher")$brks # 5 natural bins
pm25palette <- colorBin(palette="YlOrRd" , bins=pm25.bins, na.color="dimgrey") # discrete
aqi.bins<- c(0, 50, 100, 150, 200, 300, 500)
aqi.palette<- c('#00FF00','#FFFF00','#FFA500','#FF0000','#99004C','#800000')
aqi.legend.labels<- c("Good", "Moderate", "USG",
"Unhealthy", "Very Unhealthy", "Harzardous")
aqipalette <- colorBin(palette= aqi.palette, bins = aqi.bins, na.color="dimgrey")
covid.bins <- classIntervals(na.omit(c(sapply(6:15, function(z) covid[,z][[1]]))), 5, style="fisher")$brks # 5 natural bins
covidpalette <- colorBin(palette="YlOrRd" , bins=covid.bins, na.color="dimgrey") # discrete
asthma.bins <- classIntervals(na.omit(c(sapply(6:7, function(z) asthma[,z][[1]]))), 5, style="fisher")$brks # 5 natural bins
asthmapalette <- colorBin(palette="YlOrRd" , bins=asthma.bins, na.color="transparent") # discrete
svi.bins <- classIntervals(na.omit(trees$svi_pecent), 5, style="fisher")$brks # 5 natural bins
svipalette <- colorBin(palette="YlOrRd" , bins=svi.bins, na.color="transparent") # discrete
hard.bins <- classIntervals(na.omit(trees$hardship), 5, style="fisher")$brks # 5 natural bins
hardpalette <- colorBin(palette="YlOrRd" , bins=hard.bins, na.color="transparent") # discrete
##### COLOR BREAKS END #####
##### TAB SETUP START #####
##### NN START #####
nn.description <- c("These neural net models were generated by the Center for Spatial Data Science at the University of Chicago. They are all multi-stage deep neural nets incorporating readings from NASA's Aerosol Optical Depth dataset and approximately a dozen other air quality covariates. The model generates monthly results for the period between March of 2014 and December of 2018. The spatial model varies the base model by using spatial cross-validation techniques, instead of random cross-validation. The outlier model does not remove readings above 20 micrograms per cubic meter, as was done in the base model. ")
nn.source <- c("This model was generated using publicly available air quality covariates by the Center for Spatial Data Science at the University of Chicago. ")
##### NN END #####
##### AOD START #####
aod.tabname <- "aod"
aod.name <- "Aerosol Optical Depth"
aod.description <- descriptions$Description[descriptions["Variable"] == "AOD"]
aod.source <- descriptions$Source[descriptions["Variable"] == "AOD"]
##### AOD END #####
##### NDVI START #####
ndvi.tabname <- "ndvi"
ndvi.name <- "Normalized Difference Vegetation Index"
ndvi.description <- descriptions$Description[descriptions["Variable"] == "NDVI"]
ndvi.source <- descriptions$Source[descriptions["Variable"] == "NDVI"]
##### NDVI END #####
##### BRF START #####
brf.tabname <- "brf"
brf.name <- "Bidirectional Reflectance Factor"
brf.description <- descriptions$Description[descriptions["Variable"] == "BRF"]
brf.source <- descriptions$Source[descriptions["Variable"] == "BRF"]
##### BRF END #####
##### LAND COVER START #####
lc.tabname <- "landcover"
lc.name <- "Land Cover"
lc.description <- descriptions$Description[descriptions["Variable"] == "Land Cover"]
lc.source <- descriptions$Source[descriptions["Variable"] == "Land Cover"]
##### ELEVATION START #####
elevation.tabname <- "elevation"
elevation.name <- "Elevation"
elevation.description <- descriptions$Description[descriptions["Variable"] == "Elevation"]
elevation.source <- descriptions$Source[descriptions["Variable"] == "Elevation"]
##### ELEVATION END #####
##### PM2.5 START #####
pm25.tabname <- "pm25"
pm25.name <- "Particulate Matter < 2.5μm (PM2.5)"
pm25.description <- descriptions$Description[descriptions["Variable"] == "PM2.5"]
pm25.source <- descriptions$Source[descriptions["Variable"] == "PM2.5"]
##### PM2.5 END #####
##### PM10 START #####
pm10.tabname <- "pm10"
pm10.name <- "Particulate Matter < 10μm (PM10)"
pm10.description <- descriptions$Description[descriptions["Variable"] == "PM10"]
pm10.source <- descriptions$Source[descriptions["Variable"] == "PM10"]
##### PM10 END #####
##### CO START #####
co.tabname <- "co"
co.name <- "Carbon Monoxide"
co.description <- descriptions$Description[descriptions["Variable"] == "CO"]
co.source <- descriptions$Source[descriptions["Variable"] == "CO"]
##### CO END #####
##### NO2 START #####
no2.tabname <- "no2"
no2.name <- "Nitrogen Dioxide"
no2.description <- descriptions$Description[descriptions["Variable"] == "NO2"]
no2.source <- descriptions$Source[descriptions["Variable"] == "NO2"]
##### NO2 END #####
##### O3 START #####
o3.tabname <- "o3"
o3.name <- "Ozone"
o3.description <- descriptions$Description[descriptions["Variable"] == "Ozone"]
o3.source <- descriptions$Source[descriptions["Variable"] == "Ozone"]
##### O3 END #####
##### SO2 START #####
so2.tabname <- "so2"
so2.name <- "Sulfur Dioxide"
so2.description <- descriptions$Description[descriptions["Variable"] == "SO2"]
so2.source <- descriptions$Source[descriptions["Variable"] == "SO2"]
##### SO2 END #####
##### PB START #####
pb.tabname <- "pb"
pb.name <- "Lead"
pb.description <- descriptions$Description[descriptions["Variable"] == "Pb"]
pb.source <- descriptions$Source[descriptions["Variable"] == "Pb"]
##### PB END #####
##### PE START #####
pe.tabname <- "pe"
pe.name <- "Point Emissions"
pe.description <- descriptions$Description[descriptions["Variable"] == "Point Emissions"]
pe.source <- descriptions$Source[descriptions["Variable"] == "Point Emissions"]
##### PE END #####
##### ROADS START #####
roads.tabname <- "roads"
roads.name <- "Road Emissions"
roads.description <- descriptions$Description[descriptions["Variable"] == "Roads"]
roads.source <- descriptions$Source[descriptions["Variable"] == "Roads"]
##### ROADS END #####
##### TEMP START #####
temp.tabname <- "temp"
temp.name <- "Temperature"
temp.description <- descriptions$Description[descriptions["Variable"] == "Temperature"]
temp.source <- descriptions$Source[descriptions["Variable"] == "Temperature"]
##### TEMP END #####
##### PRESSURE START #####
pressure.tabname <- "pressure"
pressure.name <- "Barometric Pressure"
pressure.description <- descriptions$Description[descriptions["Variable"] == "Pressure"]
pressure.source <- descriptions$Source[descriptions["Variable"] == "Pressure"]
##### PRESSURE END #####
##### PRECIP START #####
precip.tabname <- "precip"
precip.name <- "Precipitation"
precip.description <- descriptions$Description[descriptions["Variable"] == "Precip"]
precip.source <- descriptions$Source[descriptions["Variable"] == "Precip"]
##### PRECIP END #####
##### TAB SETUP END #####
##### PLOT ADJUSTMENT START #####
master.raster$PECount[which(getValues(master.raster$PECount) == 0)] <- NA ### Needed for plotting; raster error when try to write new file
master.raster$RdDnsty[which(getValues(master.raster$RdDnsty) == 0)] <- NA
##### PLOT ADJUSTMENT END #####
##### COVID START #####
labels_covid <- sprintf(
as.character(covid$zip)
) %>% lapply(htmltools::HTML)
# zoom boundaries for COVID maps
counties.bounds <- st_bbox(large.area$geometry)
names(counties.bounds) <- c("lng1", "lat1", "lng2", "lat2")
counties.bounds <- split(unname(counties.bounds), names(counties.bounds))
chi.bounds <- st_bbox(chi.admin.map$geometry)
names(chi.bounds) <- c("lng1", "lat1", "lng2", "lat2")
chi.bounds <- split(unname(chi.bounds), names(chi.bounds))
##### COVID END #####
##### VARIABLE END #####
##### THEME START #####
chicago_blue <- "rgb(128, 206, 255)"
chicago_red <- "rgb(199, 20, 20)"
sidebar_select_gradient <- cssGradientThreeColors(
direction = "right"
,colorStart = "rgb(255, 67, 67)"
,colorMiddle = "rgb(255, 120, 120)"
,colorEnd = "rgb(255,175,175)"
,colorStartPos = 0
,colorMiddlePos = 30
,colorEndPos = 100
)
sidebar_hover_gradient <- sidebar_select_gradient
### creating custom theme object
theme_air_chicago <- shinyDashboardThemeDIY(
### general
appFontFamily = "Arial"
,appFontColor = "rgb(0,0,0)"
,primaryFontColor = "rgb(0,0,0)"
,infoFontColor = "rgb(0,0,0)"
,successFontColor = "rgb(0,0,0)"
,warningFontColor = "rgb(0,0,0)"
,dangerFontColor = "rgb(0,0,0)"
,bodyBackColor = "rgb(217,217,217)"
### header
,logoBackColor = chicago_blue
,headerButtonBackColor = chicago_blue
,headerButtonIconColor = "rgb(245,245,245)"
,headerButtonBackColorHover = chicago_blue
,headerButtonIconColorHover = "rgb(0,0,0)"
,headerBackColor = chicago_blue
,headerBoxShadowColor = "#aaaaaa"
,headerBoxShadowSize = "2px 2px 2px"
### sidebar
,sidebarBackColor = chicago_blue
,sidebarPadding = 2
,sidebarMenuBackColor = "transparent"
,sidebarMenuPadding = 0
,sidebarMenuBorderRadius = 0
,sidebarShadowRadius = "3px 5px 5px"
,sidebarShadowColor = "#aaaaaa"
,sidebarUserTextColor = "rgb(255,255,255)"
,sidebarSearchBackColor = "rgb(55,72,80)"
,sidebarSearchIconColor = "rgb(153,153,153)"
,sidebarSearchBorderColor = "rgb(55,72,80)"
,sidebarTabTextColor = "rgb(255,255,255)"
,sidebarTabTextSize = 13
,sidebarTabBorderStyle = "none none solid none"
,sidebarTabBorderColor = "rgb(35,106,135)"
,sidebarTabBorderWidth = 1
,sidebarTabBackColorSelected = sidebar_select_gradient
,sidebarTabTextColorSelected = "rgb(0,0,0)"
,sidebarTabRadiusSelected = "0px 20px 20px 0px"
,sidebarTabBackColorHover = sidebar_hover_gradient
,sidebarTabTextColorHover = "rgb(50,50,50)"
,sidebarTabBorderStyleHover = "none none solid none"
,sidebarTabBorderColorHover = "rgb(75,126,151)"
,sidebarTabBorderWidthHover = 1
,sidebarTabRadiusHover = "0px 20px 20px 0px"
### boxes
,boxBackColor = "rgb(255,255,255)"
,boxBorderRadius = 5
,boxShadowSize = "0px 1px 1px"
,boxShadowColor = "rgba(0,0,0,.1)"
,boxTitleSize = 16
,boxDefaultColor = "rgb(210,214,220)"
,boxPrimaryColor = "rgba(44,222,235,1)"
,boxInfoColor = "rgb(210,214,220)"
,boxSuccessColor = "rgba(0,255,213,1)"
,boxWarningColor = "rgb(244,156,104)"
,boxDangerColor = "rgb(255,88,55)"
,tabBoxTabColor = "rgb(255,255,255)"
,tabBoxTabTextSize = 14
,tabBoxTabTextColor = "rgb(0,0,0)"
,tabBoxTabTextColorSelected = "rgb(0,0,0)"
,tabBoxBackColor = "rgb(255,255,255)"
,tabBoxHighlightColor = "rgba(44,222,235,1)"
,tabBoxBorderRadius = 5
### inputs
,buttonBackColor = "rgb(245,245,245)"
,buttonTextColor = "rgb(0,0,0)"
,buttonBorderColor = "rgb(200,200,200)"
,buttonBorderRadius = 5
,buttonBackColorHover = "rgb(235,235,235)"
,buttonTextColorHover = "rgb(100,100,100)"
,buttonBorderColorHover = "rgb(200,200,200)"
,textboxBackColor = "rgb(255,255,255)"
,textboxBorderColor = "rgb(200,200,200)"
,textboxBorderRadius = 5
,textboxBackColorSelect = "rgb(245,245,245)"
,textboxBorderColorSelect = "rgb(200,200,200)"
### tables
,tableBackColor = "rgb(255,255,255)"
,tableBorderColor = "rgb(240,240,240)"
,tableBorderTopSize = 1
,tableBorderRowSize = 1
)
##### THEME END #####
ui <- dashboardPage(
title = "Open Air Chicago",
##### LOGO START #####
dashboardHeader(title = shinyDashboardLogoDIY(boldText = "Open Air",
mainText = "Chicago",
textSize = 16,
badgeText = "BETA",
badgeTextColor = "white",
badgeTextSize = 2,
badgeBackColor = chicago_red,
badgeBorderRadius = 3)
),
##### LOGO END #####
dashboardSidebar(sidebarMenu(id = "sidebar",
menuItem("Home", tabName = "home", icon = icon("home"),
menuSubItem("Introduction", tabName = "home", icon = icon("info")),
menuSubItem("Region Explorer", tabName = "region", icon = icon("map-marked-alt")),
menuSubItem("Health Explorer", tabName = "covid", icon = icon("medkit")),
menuSubItem("Tree Equity Tool", href = "https://rhabus.carto.com/builder/50d25399-d7c7-4cf1-9e17-0ef44c7d7315/embed_protected?", icon = icon("tree")),
menuSubItem("About", tabName = "about", icon = icon("question"))),
menuItem("EPA Sensor Data", icon = icon("envira"),
menuSubItem("PM2.5", tabName = "pm25"),
menuSubItem("PM10", tabName = "pm10"),
menuSubItem("Carbon Monoxide", tabName = "co"),
menuSubItem("Nitrogen Dioxide", tabName = "no2"),
menuSubItem("Ozone", tabName = "o3"),
menuSubItem("Sulfur Dioxide", tabName = "so2"),
menuSubItem("Lead", tabName = "pb")),
menuItem("Meteorological Data", icon = icon("thermometer-half"),
menuSubItem("Temperature", tabName = "temp"),
menuSubItem("Pressure", tabName = "pressure"),
menuSubItem("Precipitation", tabName = "precip")),
menuItem("Remote-Sensed Data", icon = icon("wifi"),
menuSubItem("Aerosol Optical Depth", tabName = "aod"),
menuSubItem("NDVI", tabName = "ndvi"),
menuSubItem("BRF", tabName = "brf"),
menuSubItem("Land Cover", tabName = "landcover"),
menuSubItem("Elevation", tabName = "elevation")),
menuItem("PM2.5 Model", tabName = "nn", icon = icon("code-branch")),
menuItem("Pollution Drivers", icon = icon("industry"),
menuSubItem("Point Emissions", tabName = "pe"),
menuSubItem("Roads", tabName = "roads")),
menuItem("Chicago Health Atlas", href = "https://chicagohealthatlas.org", icon = icon("heartbeat")),
menuItem("Downloads", icon = icon("download"), tabName = "downloads"))
),
dashboardBody(
tags$style(type = "text/css", "html, body {width:100%;height:100%}",
".leaflet .legend-circles i{
border-radius: 50%;
}
"),
theme_air_chicago,
tabItems(
##### HOME START #####
tabItem(tabName = "home",
fluidRow(
box(width = 12,
img(src='header.png', width = '100%', align = "center", style="max-width:1024px;display:block;margin:0 auto;", alt="Chicago's Open Air Quality Environment Explorer"),
h1("Explore current and historical trends of air quality in the Chicagoland area", align="center")
)),
fluidRow(
box(width = 6,
h2("What can this app do?", align = "center", style = "color: #80ceff"),
p("This R-shiny based web application provides a current snapshot and look back at air quality indicators to visualize how measured air quality has changed
across space and time. Primarily, the data presented in this application takes the form of 1 kilometer x 1 kilometer raster data, reflecting a grid of data overlaid
on top of the Greater Chicagoland area.")
),
box(width = 6,
h2("Getting Started", align = "center", style = "color: #c71414"),
p("In the menu, there are several categories of sensor data, including EPA sensors, Meteorological data, remote-sensing (satellite) data, and modeled data. Explore these
tabs to see how different metrics shed light on the air quality of the diverse areas around Chicagoland.")
)
),
fluidRow(
box(width = 6,
h2("More Information", align = "center", style = "color: #c71414"),
p("For further information about the project objectives, overview, team, and data access, visit the About tab under Home.")
),
box(width = 6,
h2("Open Source and Open Science", align = "center", style = "color: #80ceff"),
p("This project emphasizes open source code and open science data practices. To explore the code and data, visit the links below:"),
tags$a(href="https://github.com/GeoDaCenter/OpenAirQ-dashboard/tree/master/Data", "Data"),
tags$br(),
tags$a(href="https://github.com/GeoDaCenter/OpenAirQ-dashboard", "Code")
)
),
fluidRow(
box(width = 12,
h3("Open Air Chicago is a project of", align = "center", style = "color: #c71414"),
tags$hr(),
tags$a(href="https://herop.ssd.uchicago.edu/",
img(src='herop.png', width = '50%', style="display:block;max-width:200px;margin:0 auto 20px auto", alt="Healthy Regions and Policy Lab")
),
tags$a(href="https://spatial.uchicago.edu/",
img(src='CSDS_logo_4C_1.jpg', width = '50%', style="display:block;max-width:200px;margin:0 auto 20px auto", alt="Center for Spatial Data Science"),
)
)
)
),
##### HOME END #####
##### REGION EXPLORER START ####
tabItem(tabName = "region",
fluidRow(
box(width = 12,
h2("Region Explorer", align = "center"),
textOutput("region-explorer-h2")
)),
fluidRow(
box(width = 4,
helpText("Select one or multiple counties for comparison of regional trends."),
leafletOutput("homemap", height = mapheight),
actionButton("clearshapes", "Clear Selection")
),
box(width = 8,
selectizeInput("homevar", "Select Variables for Comparison:",
c("Aerosol Optical Depth" = "AOD",
"Normalized Difference Vegetation Index" = "NDVI",
"Bidirectional Reflectance Factor" = "BRF",
"PM2.5" = "PM25",
"PM10" = "PM10",
"Carbon Monoxide" = "CO",
"Nitrogen Dioxide" = "NO2",
"Ozone" = "Ozone",
"Sulfur Dioxide" = "SO2",
"Lead" = "Lead",
"Temperature" = "Temp",
"Barometric Pressure" = "Pressure"),
options = list(maxItems = 7)),
plotlyOutput("homeplot", height = 500),
column(width = 2,
checkboxGroupInput("homecheck", label = "",
choices = c("Show Mean" = "mean",
"Rescale Data" = "rescale"),
selected = c("mean"),
width = '100%',
inline = TRUE)),
column(width = 10,
sliderTextInput("timeBounds", "Select Time Bounds:",
choices = format(seq.Date(as.Date("2014/01/01"), as.Date("2018/12/01"), by="month"),
"%Y/%m"),
selected = c("2014/01", "2018/12"), grid = FALSE)),
column(width = 12,
plotlyOutput("distplot", height = 500)))
)),
##### REGION EXPLORER END #####
##### ABOUT START #####
tabItem(tabName = "about",
fluidRow(
box(width = 12,
h2("About", align = "center"),
textOutput("abouttext")
)),
fluidRow(
box(width = 6,
h1("Overview", align = "center", style = "color: #80ceff"),
p("Open Air Chicago is an interactive dashboard providing
information on air quality for the greater Chicagoland area
including Milwaukee. It includes direct measures of air quality
as well as variables known to affect or relate to these variables.
Each of the variables has an individual page with a
variable description, source information, and interactive visualization.
Additionally, the \"Home\" tab offers the option to explore broader trends
within the data for a single variable or among several variables both at
the broader Chicagoland scale and the individual county level. All data
used to generate the graphs and maps on the dashboard are available for
access on the \"Downloads\" tab.")
),
box(width = 6,
h2("Objectives", align = "center", style = "color: #c71414"),
p("The primary goal of this dashboard is to provide both researchers and the public at large with clean, free, and easily accessible data for all things air quality. While all data used in the dashboard is technically available for free online, the numerous formats, sources, and options provide for an unwelcoming landscape. By streamlining the process through which the data is accessed, the hope is to enable more people to spend more time actually analyzing the data and working to improve air quality. Additionally, Open Air Chicago hopes to do this by offering data visualization options to explore individual variable data as well as relationships between variables over time.")
)),
fluidRow(
box(width = 6,
h2("Data", align = "center", style = "color: #c71414"),
p("All data used to create the dashboard is available online free of charge. Sources include the Environmental Protection Agency (EPA), National Aeronautics and Space Administration (NASA), National Oceanic and Atmospheric Association (NOAA), United States Geological Survey (USGS), and OpenStreetMap. Specific sourcing information is available on individual dashboard pages. County-level aggregates for all variables are available for download at a monthly and quarterly temporal resolution as CSV files on the “Downloads” tab. Also available on the “Downloads” tab is a GeoTiff raster file containing all of the 1km resolution gridded data.")
),
box(width = 6,
h2("Methodology", align = "center", style = "color: #80ceff"),
p("In addition to differing in source and format, the raw data also exists at a variety of spatial and temporal resolutions. All data was aggregated to a standard, 1km resolution grid at both monthly and quarterly intervals. For the EPA sensor data, the gridded values were extracted from an Inverse Distance Weighted interpolation of sensor averages. Interpolated values for variables with fewer sensors will be less accurate than those with more sensors. Due to data availability, particularly with NASA’s remote-sensed Aerosol Optical Depth, individual variable pages provide visualizations of the quarterly aggregates to maximize coverage. For data not originally provided at a 1km resolution, unless otherwise noted on the “Source” tab on each variable page, the value assigned to each 1km cell is the mean of all measured values within it.")
)),
fluidRow(
box(width = 6,
h2("Contributors", align="center"),
p("Below are the contributors to the Open Air Chicago project."),
tags$ul(
tags$li(tags$a(href="https://github.com/Makosak", "Marynia Kolak")),
tags$li(tags$a("Andrew Morse", href = "https://github.com/andrewjmorse")),
tags$li(tags$a("James Keane", href = "https://github.com/yahmskeano")),
tags$li(tags$a("Qiwei Lin", href = "https://github.com/QWL55")),
tags$li(tags$a("Dylan Halpern", href = "https://github.com/nofurtherinformation/"))
)
)
)
),
##### ABOUT END #####
##### COVID START #####
tabItem(tabName = "covid",
fluidRow(
box(width = 12,
sliderInput(paste("covid", "dt", sep = "_"), "Select week:",
min = start_date,
max = end_date,
value = end_date,
timeFormat = "%Y/%m/%d",
step = as.difftime(7, units = "days"),
animate = animationOptions(interval = 2000)))
),
fluidRow(
box(width = 6,
selectInput(paste("covid_map_left", "sensor", sep = "_"),
"Select Variable for Sensors",
c("Air Quality Index" = "aqi",
"PM2.5" = "pm25",
"None" = "none"),
selected = "aqi"),
selectInput(paste("covid_map_left", "choropleth", sep = "_"),
"Select Variable for Regions",
c("Asthma ED Visits (0-18)" = "asthma018",
"Asthma ED Visits (65+)" = "asthma65",
"COVID-19 Cases" = "covid",
"PM2.5 (Historical 5-Year)" = "pm25",
"Social Vulnerability Index" = "svi",
"None" = "none"),
selected = "asthma018"),
leafletOutput("covid_map_left", height = mapheight)),
box(width = 6,
selectInput(paste("covid_map_right", "sensor", sep = "_"),
"Select Variable for Sensors",
c("Air Quality Index" = "aqi",
"PM2.5" = "pm25",
"None" = "none"),
selected = "aqi"),
selectInput(paste("covid_map_right", "choropleth", sep = "_"),
"Select Variable for Regions",
c("Asthma ED Visits (0-18)" = "asthma018",
"Asthma ED Visits (65+)" = "asthma65",
"COVID-19 Cases" = "covid",
"PM2.5 (Historical 5-Year)" = "pm25",
"Social Vulnerability Index" = "svi",
"None" = "none"),
selected = "covid"),
leafletOutput("covid_map_right", height = mapheight)))),
# fluidRow(box(width = 12,
# plotlyOutput("covid_plot", height = mapheight)))),
##### COVID END #####
##### NN START #####
tabItem(tabName = "nn",
fluidRow(
box(width = 4,
tabsetPanel(
tabPanel(title = "Description",
h3("PM2.5 Model"),
p(nn.description)),
tabPanel(title = "Source",
h4("Data Source"),
p(nn.source))),
fluidRow(
column(width = 5,
add_prompt(
radioGroupButtons(inputId = "lc_chi_zoom",
"Set View",
c("21 Counties" = "lac",
"Chicago" = "chi")),
position = "bottom", message = "Zoom in or out of map",
type = "info", animate = TRUE
)),
column(width = 7,
add_prompt(
radioGroupButtons(paste("nn", "rad", sep = "_"), "Select Color Scale",
c("Overall" = "ovr", "Yearly" = "yr", "Monthly" = "mon"),
selected = "mon"),
position = "bottom", message = "Select if map color should be \n relative to all, year's, or selected predictions",
type = "info", animate = TRUE
)),
column(width = 7,
radioGroupButtons(paste("nn", "mod", sep = "_"), "Select Model",
c("Base" = "base", "Spatial" = "spat", "Outliers" = "out"),
selected = "base")),
column(width = 7,
radioGroupButtons(paste("nn", "mod", "c", sep = "_"), "Select Color Palette (Model)",
c("Base" = "base", "Spatial" = "spat", "Outliers" = "out"),
selected = "base")),
column(width = 12,
sliderTextInput("nn_dt", "Select Month:",
choices = format(seq.Date(as.Date("2014/01/01"), as.Date("2018/12/01"), by="month"),
"%Y/%m"),
selected = "2016/07", grid = FALSE)))),
box(width = 8,
leafletOutput(paste("nn", "map", sep = "_"),height = "90vh"))
)),
##### NN END #####
##### HISTORICAL DATA TABS START #####
generateQuarterlyTab(aod.tabname, aod.name, aod.description, aod.source),
generateQuarterlyTab(ndvi.tabname, ndvi.name, ndvi.description, ndvi.source),
generateQuarterlyTab(brf.tabname, brf.name, brf.description, brf.source),
tabItem(tabName = "landcover",
use_prompt(),
fluidRow(
box(width = 4,
tabsetPanel(
tabPanel(title = "Description",
h3(lc.name),
p(lc.description)),
tabPanel(title = "Source",
h4("Data Source"),
p(lc.source))),
add_prompt(
radioGroupButtons(inputId = "lc_chi_zoom",
"Set View",
c("21 Counties" = "lac",
"Chicago" = "chi")),
position = "bottom", message = "Zoom in or out of map",
type = "info", animate = TRUE
)),
box(width = 8,
leafletOutput("lc_map", height = "90vh"),
radioGroupButtons(inputId = "lc_choose",
"Select Index",
c("Green" = "grn_ndx",
"Gray" = "gry_ndx",
"Blue" = "blu_ndx"))
)
)
),
generateOneTimeTab(elevation.tabname, elevation.name, elevation.description, elevation.source),
generateDynaTab(pm25.tabname, pm25.name, pm25.description, pm25.source),
generateDynaTab(pm10.tabname, pm10.name, pm10.description, pm10.source),
generateDynaTab(co.tabname, co.name, co.description, co.source),
generateDynaTab(no2.tabname, no2.name, no2.description, no2.source),
generateDynaTab(o3.tabname, o3.name, o3.description, o3.source),
generateDynaTab(so2.tabname, so2.name, so2.description, so2.source),
generateDynaTab(pb.tabname, pb.name, pb.description, pb.source),
generateOneTimeTab(pe.tabname, pe.name, pe.description, pe.source,
mapviewselected = "chi"),
generateOneTimeTab(roads.tabname, roads.name, roads.description, roads.source),
generateDynaTab(temp.tabname, temp.name, temp.description, temp.source),
generateDynaTab(pressure.tabname, pressure.name, pressure.description, pressure.source),
generateDynaTab(precip.tabname, precip.name, precip.description, precip.source),
##### VULNERABILITY START #####
# generateOneTimeTab("svi", "Social Vulnerability Index", "", ""),
#
# generateOneTimeTab("hardind", "Economic Hardship Index", "", ""),
##### VULNERABILITY END #####
##### DOWNLOADS START #####
tabItem(tabName = "downloads",
fluidRow(
box(width = 12,
h1("Downloads", align = "center")
)),
fluidRow(
box(width = 4,
h3("CSV", align = "center"),
p("EPA and FAA data are given by sensor, with longitude (X) and latitude (Y) coordinates.",
align = "center"),
downloadBttn("monthly_epa_data",
label = "Download Monthly EPA Data",
style = "simple"),
downloadBttn("quarterly_epa_data",
label = "Download Quarterly EPA Data",
style = "simple"),
downloadBttn("monthly_faa_data",
label = "Download Monthly FAA Data",
style = "simple"),
downloadBttn("quarterly_faa_data",
label = "Download Quarterly FAA Data",
style = "simple")),
box(width = 4,
h3("Raster", align = "center"),
p("Warning: requires processing time", align = "center"),
p("The monthly raster contains data for EPA and FAA variables with monthly IPW interpolations. The quarterly raster contains quarterly interpolations, as well as other available rasters, except for neural net outputs, which are contained in the neural net download.",
align = "center"),
downloadBttn("monthly_raster",
label = "Download 1km Monthly Raster",
style = "simple"),
downloadBttn("master_raster",
label = "Download 1km Quarterly Raster",
style = "simple"),
downloadBttn("nn_raster",
label = "Download Neural Net Outputs",
style = "simple")),
box(width = 4,
h3("GeoJSON", align = "center"),
p("EPA and FAA data are given by sensor, in spatial format.",
align = "center"),
downloadBttn("monthly_epa_data_geo",
label = "Download Monthly EPA Data",
style = "simple"),
downloadBttn("quarterly_epa_data_geo",
label = "Download Quarterly EPA Data",
style = "simple"),
downloadBttn("monthly_faa_data_geo",
label = "Download Monthly FAA Data",
style = "simple"),
downloadBttn("quarterly_faa_data_geo",
label = "Download Quarterly FAA Data",
style = "simple"))
))
##### DOWNLOADS END #####
)))
server <- function(input, output) {
##### HOME START #####
abt.count <- reactiveValues(val = 0) #Create counter to track hold of last shape clicked
all.fips <- reactiveValues(fips = c())
output$homemap <- renderLeaflet({
leaflet(large.area) %>%
addProviderTiles(provider = "OpenStreetMap.HOT") %>%
setView(lat = "41.97736", lng = "-87.62255", zoom = 7) %>%
leaflet::addPolygons(weight = 1,
color = "gray",
layerId = large.area$FIPS,
fillOpacity = 0.2,
label = large.area$COUNTYNAME,
highlight = highlightOptions(
weight = 2,
color = "#666",
fillOpacity = 0.7,
bringToFront = TRUE))
})
observeEvent(input$clearshapes,{
if(input$sidebar == "region") {
home.proxy <- leafletProxy("homemap")
if(input$clearshapes){
home.proxy %>%
removeShape(layerId = c(paste("Highlighted", all.fips$fips)))
all.fips$fips <- c()
}
# Reset selectize input to clear choices
updateSelectizeInput(session = getDefaultReactiveDomain(), "homevar",
choices=c("Aerosol Optical Depth" = "AOD",
"Normalized Difference Vegetation Index" = "NDVI",
"Bidirectional Reflectance Factor" = "BRF",
"PM2.5" = "PM25",
"PM10" = "PM10",
"Carbon Monoxide" = "CO",
"Nitrogen Dioxide" = "NO2",
"Ozone" = "Ozone",
"Sulfur Dioxide" = "SO2",
"Lead" = "Lead",
"Temperature" = "Temp",
"Barometric Pressure" = "Pressure"),
options = list(maxItems = 7))
}
})
# Highlight clicked counties, unhighlight double clicked, zoom to center of all selected
observeEvent(input$homemap_shape_click, {
if(input$sidebar == "region") { #Optimize Dashboard speed by not observing outside of tab
this.fips <- input$homemap_shape_click$id
home.proxy <- leafletProxy("homemap")
if(nchar(this.fips) <= 5) { #Make sure that selected layer not highlighted
abt.count$val <- abt.count$val + 1
all.fips$fips[abt.count$val] <- this.fips
for(i in 1:length(all.fips$fips)) { #Highlight selected counties
home.proxy <- home.proxy %>%
addPolygons(data = large.area[which(large.area$FIPS %in% all.fips$fips[i]),][1],
color = "red", layerId = paste("Highlighted", all.fips$fips[i]),
label = paste(large.area$COUNTYNAME[which(large.area$FIPS %in% all.fips$fips[i])], " County"))