-
Notifications
You must be signed in to change notification settings - Fork 1
/
DecemberCopyOfApp.R
1842 lines (1393 loc) · 61.2 KB
/
DecemberCopyOfApp.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
library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(dashboardthemes)
library(leaflet)
library(rgdal)
library(sf)
library(lubridate)
library(grDevices)
library(plotly)
library(data.table)
library(raster)
library(scales)
##### DATA LOADING START #####
source("DashFunctions.R")
master.raster <- stack("Data/Master_Raster.tif")
raster.names <- read.csv("Data/Master_Raster_Names.csv")
names(master.raster) <- raster.names$x
large.area <- st_read("Data/LargeAreaCounties")
large.area$COUNTYNAME <- as.character(large.area$COUNTYNAME)
descriptions <- read.csv("Data/Description.csv", stringsAsFactors = F)
county.avgs <- read.csv("Data/county_averages_monthly.csv")
county.avgs$Name <- as.character(county.avgs$Name)
var.avgs <- colMeans(county.avgs[,4:ncol(county.avgs)], na.rm = T)
epa.points <- st_read("Data/EPA_Points")
chi.map <- st_read("Data/Chicago")
#chi.map <- sf::st_transform(chi.map, CRS('+proj=longlat +datum=WGS84'))
cdph.permits <- st_read("Data/CDPH_Permits")
#NN Data Loading
nn.raster <- stack("Data/NN_Results.tif")
nn.names <- read.csv("Data/NN_Raster_Names.csv")
names(nn.raster) <- nn.names$nn_names
##### DATA LOADING END #####
##### VARIABLE START #####
mapheight = 500
##### NN START #####
nn.description <- c("This model was generated by the Center for Spatial Data Science at the University of Chicago. It is a multi-stage model incorporating readings from NASA's Aerosol Optical Depth dataset and approximately a dozen other air quality covariates. The model was run once per month for a period between March of 2014 and December of 2018. ")
nn.source <- c("This Neural Net was generated using a dozen 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"]
##### 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 #####
##### 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 <- cssGradientThreeColors(
# direction = "right"
# ,colorStart = chicago_red
# ,colorMiddle = "rgba(199,80,80,1)"
# ,colorEnd = "rgba(199,110,110, 1)"
# ,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(
##### 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")),
menuItem("About", tabName = "about", icon = icon("info")),
menuItem("Neural Net Model", tabName = "nn", icon = icon("code-branch")),
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("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("Human Emissions", icon = icon("industry"),
menuSubItem("Point Emissions", tabName = "pe"),
menuSubItem("Roads", tabName = "roads")),
menuItem("Meteorological Data", icon = icon("thermometer-half"),
menuSubItem("Temperature", tabName = "temp"),
menuSubItem("Pressure", tabName = "pressure")),
#menuSubItem("Precipitation", tabName = "precip")),
menuItem("Downloads", icon = icon("download"), tabName = "downloads"))
),
dashboardBody(
theme_air_chicago,
tabItems(
##### HOME START #####
tabItem(tabName = "home",
fluidRow(
box(width = 12,
h1("Home", align = "center")
)),
fluidRow(
box(width = 4,
leafletOutput("homemap", height = mapheight),
checkboxGroupInput("homecheck", label = "", c("Show Mean" = "mean",
"Rescale Data" = "rescale"),
selected = c("mean"),
width = '100%',
inline = TRUE)),
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 = 445),
actionButton("clearshapes", "Clear Selection")))
),
##### HOME END #####
##### ABOUT START #####
tabItem(tabName = "about",
fluidRow(
box(width = 12,
h1("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 16 examined 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,
h1("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,
h1("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,
h1("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.")
))
),
##### ABOUT END #####
##### NN START #####
tabItem(tabName = "nn",
fluidRow(
box(width = 4,
tabsetPanel(
tabPanel(title = "Description",
h3("Neural Net Model"),
p(nn.description)),
tabPanel(title = "Source",
h4("Data Source"),
p(nn.source))),
radioGroupButtons(inputId = paste("nn", "chi_zoom", sep = "_"),
"Set View",
c("21 Counties" = "lac",
"Chicago" = "chi"))
),
box(width = 8,
sliderInput(paste("nn", "dt", sep = "_"), "Select month:",
min = strptime("2014/03/01","%Y/%m/%d"),
max = strptime("2018/12/31","%Y/%m/%d"),
value = strptime("2016/07/01","%Y/%m/%d"),
timeFormat = "%Y/%m",
step = as.difftime(30, units = "days"),
animate = animationOptions(interval = 2000)),
leafletOutput(paste("nn", "map", sep = "_"),height = mapheight),
radioGroupButtons(paste("nn", "rad", sep = "_"), "Select Color Palette",
c("Overall" = "ovr", "Yearly" = "yr", "Monthly" = "mon"),
selected = "ovr"))
)),
##### NN END #####
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),
##### LAND USE START #####
tabItem(tabName = "landcover",
fluidRow(
box(width = 4,
tabsetPanel(
tabPanel(title = "Description",
h3(lc.name),
p(lc.description)),
tabPanel(title = "Source",
h4("Data Source"),
p(lc.source))),
radioGroupButtons(inputId = "lc_chi_zoom",
"Set View",
c("21 Counties" = "lac",
"Chicago" = "chi"))),
box(width = 8,
leafletOutput("lc_map", height = mapheight),
radioGroupButtons(inputId = "lc_choose",
"Select Index",
c("Green" = "grn_ndx",
"Gray" = "gry_ndx",
"Blue" = "blu_ndx"))
)
)
),
##### LAND USE END #####
generateOneTimeTab(elevation.tabname, elevation.name, elevation.description, elevation.source),
generateQuarterlyTab(pm25.tabname, pm25.name, pm25.description, pm25.source),
generateQuarterlyTab(pm10.tabname, pm10.name, pm10.description, pm10.source),
generateQuarterlyTab(co.tabname, co.name, co.description, co.source),
generateQuarterlyTab(no2.tabname, no2.name, no2.description, no2.source),
generateQuarterlyTab(o3.tabname, o3.name, o3.description, o3.source),
generateQuarterlyTab(so2.tabname, so2.name, so2.description, so2.source),
generateQuarterlyTab(pb.tabname, pb.name, pb.description, pb.source),
generateOneTimeTab(pe.tabname, pe.name, pe.description, pe.source),
generateOneTimeTab(roads.tabname, roads.name, roads.description, roads.source),
generateQuarterlyTab(temp.tabname, temp.name, temp.description, temp.source),
generateQuarterlyTab(pressure.tabname, pressure.name, pressure.description, pressure.source),
##### PRECIPITATION START #####
tabItem(tabName = "precip",
fluidRow(
box(
width = 4,
h3("Precipitation"),
p("Aerosol optical depth is a measure of the extinction of the solar beam by dust
and haze. In other words, particles in the atmosphere (dust, smoke, pollution)
can block sunlight by absorbing or by scattering light."), #### NEATER DEFINITION
br(),
h4("Data Source"),
p("We use data directly from NASA. The Moderate Resolution Imaging Spectroradiometer
(MODIS) satellite provides daily global coverage, but the 10 km resolution of its
aerosol optical depth (AOD) product is not suitable for studying spatial variability
of aerosols in urban areas. Recently, a new Multi-Angle Implementation of Atmospheric
Correction (MAIAC) algorithm was developed for MODIS which provides AOD at 1 km
resolution.") #### FIX
),
box(width = 8,
sliderInput("precip_dt", "Select quarter:",
min = strptime("2014/01/01","%Y/%m/%d"),
max = strptime("2018/12/31","%Y/%m/%d"),
value = strptime("2016/07/01","%Y/%m/%d"),
timeFormat = "%Y/%m",
step = as.difftime(92, units = "days"),
animate = animationOptions(interval = 2000)),
leafletOutput("precip_map",height = mapheight))
)),
##### PRECIPITATION END #####
##### DOWNLOADS START #####
tabItem(tabName = "downloads",
fluidRow(
box(width = 12,
h1("Downloads", align = "center")
)),
fluidRow(
box(width = 4,
h3("CSV", align = "center"),
downloadBttn("monthly_data",
label = "Download Monthly County Data",
style = "simple"),
downloadBttn("quarterly_data",
label = "Download Quarterly County Data",
style = "simple")),
box(width = 4,
h3("Raster", align = "center"),
downloadBttn("master_raster",
label = "Download 1km Resolution Raster",
style = "simple"),
downloadBttn("master_raster_names",
label = "Download Raster Layer Names",
style = "simple")),
box(width = 4,
h3("Shapefile", align = "center"),
downloadBttn("large_area_counties",
label = "Download County Shapefile",
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 == "home") {
home.proxy <- leafletProxy("homemap")
if(input$clearshapes){
home.proxy %>%
removeShape(layerId = c(paste("Highlighted", all.fips$fips))) %>%
setView(lat = 41.97736,
lng = -87.62255,
zoom = 7)
all.fips$fips <- c()
}
}
})
# Highlight clicked counties, unhighlight double clicked, zoom to center of all selected
observeEvent(input$homemap_shape_click, {
if(input$sidebar == "home") { #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"))
}
} else {
high.fips <- substring(this.fips, first = 13) #Extract FIPS from Layer Id
home.proxy <- home.proxy %>%
removeShape(layerId = c(paste("Highlighted", all.fips$fips))) #Clear highlighted shapes from proxy
all.fips$fips <- all.fips$fips[-which(all.fips$fips %in% high.fips)] #Remove fips from list of selected fips
abt.count$val <- abt.count$val - 1 #Adjust for removed value
for(i in 1:length(all.fips$fips)) { #Highlight all remaining 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"))
}
}
view.lat <- mean(large.area$LAT[which(large.area$FIPS %in% all.fips$fips)])
view.lon <- mean(large.area$LON[which(large.area$FIPS %in% all.fips$fips)])
if(length(all.fips$fips) == 0) {
view.lat <- 41.97736
view.lon <- -87.62255
}
home.proxy %>%
setView(lng = view.lon,
lat = view.lat,
zoom = 7)
}
})
output$homeplot <- renderPlotly({
##### Transform averages into plotly friendly format
vars <- input$homevar
if(is.null(vars)){
p <- plot_ly() %>% config(displayModeBar = F) %>%
layout(legend = list(x = .5, y = 100, orientation = "h"))
p
return()
}
these.vars.avgs <- list()
for(i in 1:length(vars)) {
these.vars.avgs[[i]] <- var.avgs[which(grepl(vars[i], names(var.avgs)))]
if ("rescale" %in% input$homecheck) {
these.vars.avgs[[i]] <- rescale(these.vars.avgs[[i]])
}
}
months <- 1:12
years <- 2014:2018
dates <- c()
for(i in 1:length(years)) {
this.yr <- paste(months, "01", years[i], sep = "-")
dates <- c(dates, this.yr)
}
dates <- mdy(as.character(dates))
highlighted <- all.fips$fips
if(length(all.fips$fips == 0)) {
selected.fips <- 0
}
selected.fips <- which(county.avgs$FIPS %in% all.fips$fips)
blues <- c("#033682", "#0356a3", "#0083d9", "#66ccff", "#c9e8ff")
reds <- c("#9c1500", "#f52302", "#ff6e57", "#ff9a8a", "#ffc8bf")
greens <- c("#165422", "#0b9926", "#14ff41", "#91faa5", "#d6ffde")
yellows <- c("#8f8a00", "#d4cc04", "#faf005", "#f5f190", "#faf8c3")
grays <- c("#343d46", "#4f5b66", "#65737e", "#a7adba", "#c0c5ce")
colors <- data.frame(blues, reds, greens, yellows, grays)
home.checkbox <- ("mean" %in% input$homecheck)
p <- plot_ly() %>% config(displayModeBar = F) %>%
layout(legend = list(x = .5, y = 100, orientation = "h"))
for(i in 1:length(these.vars.avgs)) {
if(home.checkbox == T) { # Add overall variable mean line
p <- add_trace(p,
x = dates,
y = these.vars.avgs[[i]],
type = "scatter",
mode = "lines",
opacity = 1,
line = list(dash = "dot", color = colors[1,i]),
name = paste("Average", vars[i], sep = " "),
text= paste("Average", vars[i], sep = " "))
}
if(length(selected.fips) != 0) { # Add county variable mean line
for(j in 1:length(selected.fips)) {
if("rescale" %in% input$homecheck) {
p <- add_trace(p,
x = dates,
y = rescale(as.numeric(county.avgs[selected.fips[j],names(these.vars.avgs[[i]])])),
type = "scatter",
mode = "lines",
opacity = .5,
line = list(color = colors[j+1,i]),
name = paste(county.avgs$Name[selected.fips[j]], "County", vars[i], sep = " "),
text= paste(county.avgs$Name[selected.fips[j]], "County", vars[i], sep = " "))
} else {
p <- add_trace(p,
x = dates,
y = as.numeric(county.avgs[selected.fips[j],names(these.vars.avgs[[i]])]),
type = "scatter",
mode = "lines",
opacity = .5,
line = list(color = colors[j+1, i]),
name = paste(county.avgs$Name[selected.fips[j]], "County", vars[i], sep = " "),
text= paste(county.avgs$Name[selected.fips[j]], "County", vars[i], sep = " "))
}
}}
}
p
})
##### HOME END #####
##### ABOUT START #####
##### ABOUT END #####
##### NN START #####
output$nn_map <- renderLeaflet({
this.nn.name <- "NN_7_16"
in.pal <- "ovr"
nn.pal <- palFromLayer(this.nn.name, style = in.pal, raster = nn.raster)
dashMap(this.nn.name, nn.pal, raster = nn.raster, area = large.area,
layerId = large.area$FIPS)
})
observe({
if (input$sidebar == "nn") { #Optimize Dashboard speed by not observing outside of tab
in.date <- input$nn_dt
this.nn.name <- getLayerName(in.date, "NN", period = "mon")
## Stopgap fix to not crash app; model missing Jan/Feb 2014 and 2015
if(this.nn.name == "NN_1_15" || this.nn.name == "NN_2_15") {
this.nn.name <- "NN_3_15"
}
in.pal <- input$nn_rad
nn.pal <- palFromLayer(this.nn.name, style = in.pal, raster = nn.raster)
sliderProxy("nn_map", this.nn.name, nn.pal, raster = nn.raster)
}
})
observeEvent(input$nn_map_shape_click, {
if(input$sidebar == "nn") { #Optimize Dashboard speed by not observing outside of tab
if(input$nn_chi_zoom == "lac") {
click <- input$nn_map_shape_click
zoomMap("nn_map", click, large.area)
}
else if (input$nn_chi_zoom == "chi") {
click <- input$nn_map_shape_click
zoomChiMap("nn_map", click, chi.map)
}
}
})
observeEvent(input$nn_chi_zoom, {
if(input$sidebar == "nn") {
if(input$nn_chi_zoom == "chi") {
chiView("nn_map", chi.map)
}
else if (input$nn_chi_zoom == "lac") {
lacView("nn_map", large.area)
}
}
})
##### NN END #####
output$aod_map <- renderLeaflet({
this.aod.name <- "AOD_3_16"
in.pal <- "ovr"
aod.pal <- palFromLayer(this.aod.name, style = in.pal, raster = master.raster)
dashMap(this.aod.name, aod.pal, raster = master.raster, area = large.area,
layerId = large.area$FIPS)
})
observe({
if (input$sidebar == "aod") { #Optimize Dashboard speed by not observing outside of tab
in.date <- input$aod_dt
this.aod.name <- getLayerName(in.date, "AOD")
in.pal <- input$aod_rad
aod.pal <- palFromLayer(this.aod.name, style = in.pal, raster = master.raster)
sliderProxy("aod_map", this.aod.name, aod.pal, raster = master.raster)
}
})
observeEvent(input$aod_map_shape_click, {
if(input$sidebar == "aod") { #Optimize Dashboard speed by not observing outside of tab
if(input$aod_chi_zoom == "lac") {
click <- input$aod_map_shape_click
zoomMap("aod_map", click, large.area)
}
else if (input$aod_chi_zoom == "chi") {
click <- input$aod_map_shape_click
zoomChiMap("aod_map", click, chi.map)
}
}
})
observeEvent(input$aod_chi_zoom, {
if(input$sidebar == "aod") {
if(input$aod_chi_zoom == "chi") {
chiView("aod_map", chi.map)
}
else if (input$aod_chi_zoom == "lac") {
lacView("aod_map", large.area)
}
}
})
output$ndvi_map <- renderLeaflet({
this.ndvi.name <- "NDVI_3_16"
in.pal <- "ovr"
ndvi.pal <- palFromLayer(this.ndvi.name, style = in.pal, colors = c("lightblue", "yellow", "lightgreen", "green", "darkgreen"),
raster = master.raster)
dashMap(this.ndvi.name, ndvi.pal, raster = master.raster, area = large.area,
layerId = large.area$FIPS)
})
observe({
if (input$sidebar == "ndvi") {
in.date <- input$ndvi_dt
this.ndvi.name <- getLayerName(in.date, "NDVI")
in.pal <- input$ndvi_rad
ndvi.pal <- palFromLayer(this.ndvi.name, style = in.pal, colors = c("lightblue", "yellow", "lightgreen", "green", "darkgreen"),
raster = master.raster)
sliderProxy("ndvi_map", this.ndvi.name, ndvi.pal, raster = master.raster)
}
})
observeEvent(input$ndvi_map_shape_click, {
if(input$sidebar == "ndvi") { #Optimize Dashboard speed by not observing outside of tab
if(input$ndvi_chi_zoom == "lac") {
click <- input$ndvi_map_shape_click
zoomMap("ndvi_map", click, large.area)
}
else if (input$ndvi_chi_zoom == "chi") {
click <- input$ndvi_map_shape_click
zoomChiMap("ndvi_map", click, chi.map)
}
}
})
observeEvent(input$ndvi_chi_zoom, {
if(input$sidebar == "ndvi") {
if(input$ndvi_chi_zoom == "chi") {
chiView("ndvi_map", chi.map)
}
else if (input$ndvi_chi_zoom == "lac") {
lacView("ndvi_map", large.area)
}
}
})
output$brf_map <- renderLeaflet({
this.brf.name <- "BRDF_3_16"
in.pal <- "ovr"
brf.pal <- palFromLayer(this.brf.name, style = in.pal, colors = c("black", "white"), raster = master.raster)
brf.map <- dashMap(this.brf.name, brf.pal, raster = master.raster, area = large.area, layerId = large.area$FIPS)
})
observe({
if (input$sidebar == "brf") {
in.date <- input$brf_dt
this.brf.name <- getLayerName(in.date, "BRDF")
in.pal <- input$brf_rad
brf.pal <- palFromLayer(this.brf.name, style = in.pal, colors = c("black", "white"), raster = master.raster)
sliderProxy("brf_map", this.brf.name, brf.pal, raster = master.raster)
}
})
observeEvent(input$brf_map_shape_click, {
if(input$sidebar == "brf") { #Optimize Dashboard speed by not observing outside of tab
if(input$brf_chi_zoom == "lac") {