forked from annawit/WQRepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_legend.R
938 lines (826 loc) · 46.3 KB
/
test_legend.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
##install.packages("shiny"); install.packages("shinythemes"); install.packages("shinyWidgets")
##install.packages("leaflet"); install.packages("leaflet.extras")
##install.packages("plotly"); install.packages("ggplot2")
##install.packages("viridis")
##install.packages("RColorBrewer")
library(shiny); library(shinythemes); library(shinyWidgets)
library(leaflet); library(leaflet.extras)
library(plotly);library(ggplot2)
library(viridis)
library(RColorBrewer)
library(tools); library(tidyr)
library(tidyverse); library(lubridate); library(dplyr)
load("finaldata.RData")
# 1. UI ----
ui <- fluidPage(
theme = shinytheme("flatly"),
navbarPage("Continuous Dissolved Oxygen Visualizer",
# 1.1 Select from map ----
tabPanel("Select from map",
sidebarLayout(position = "right",
sidebarPanel(
style = "background: white",
# __1.1.1 Station summary text and table ----
wellPanel(
uiOutput("youhavechosen"),
hr(),
plotlyOutput("samplect") # sample counts
),
# __1.1.2 Table columns selector ----
wellPanel(
checkboxGroupButtons(
inputId = "tablecolumnselector",
label = "Select table columns to display:",
choices = names(dta[,c(1:19,22:25)]),
selected = c("Station Description",
"Sample Time",
"Dissolved Oxygen (mg/L)",
"Dissolved Oxygen Saturation (%)",
"DO Status")
)
)
),
# __1.1.3 Leaflet map and data table ----
mainPanel(
wellPanel(
tags$style(type = "text/css", "#map {height: calc(80vh - 80px) !important;}"),
leafletOutput("map")),
wellPanel(
DT::dataTableOutput("table"),
style = "background: white")
)
)
),
# 1.2 Overview plots ----
tabPanel("Overview Plots",
tabsetPanel(
# __1.2.1 Sample Summary ----
tabPanel("Sample Summary",
br(),
sidebarLayout(
sidebarPanel(
width = 3,
wellPanel(
selectInput(inputId = "plottype",
"Select:",
choices = c("By Site" = "Station Description",
"By Time" = "month",
"By Spawning" = "Spawning",
"By DO Criteria" = "DO Limit")
)
),
wellPanel(
tableOutput("site")
)
),
mainPanel(
wellPanel(
HTML(paste(tags$h5("Click and drag in the figure to zoom. Double click to zoom out."))),
style = "background: white"
),
wellPanel(
plotlyOutput("summaryplot", height = 800),
style = "background: white"
)
)
)
),
# __1.2.2 Minimum Dissolved Oxygen ----
tabPanel("Minimum Dissolved Oxygen",
br(),
sidebarLayout(
sidebarPanel(
width = 3,
checkboxGroupInput(
inputId = "estuary_site",
label = "Select Estuary Sites:",
choices = c("10523-ORDEQ Nestucca R at Cloverdale",
"11856-ORDEQ Nehalem River at Foley Road (Roy Creek Campground)",
"13421-ORDEQ Wilson River at Hwy 101",
"13428-ORDEQ Dougherty Slough at Hwy 101",
"13429-ORDEQ Dougherty Slough at Wilson River Loop Road (Tillamook)",
"13430-ORDEQ Hoquarten Slough at Hwy 101 (Tillamook)",
"13431-ORDEQ Trask River at Netarts Road (Hwy. 6)",
"34440-ORDEQ Hall Slough at Goodspeed Road (Tillamook, OR)",
"Sand Lake Estuary Beltz Property Upper Channel",
"Sand Lake Estuary Beltz Property at Tigegate on inside of Dike",
"Sand Lake Estuary Beltz Property at Tigegate on outside of Dike",
"Sand Lake Estuary Beltz Property Reference Slough in Lower Bay",
"Sand Lake Estuary Channel Below Beaver Dam",
"Sand Lake Estuary Side Channel above Beaver Dam",
"Sand Lake Estuary North (SandBeach Entrance)",
"Sand Lake Estuary Central (Whalen Isand Br)",
"Sand Lake Estuary South (Sitka Channel)"),
selected = c("10523-ORDEQ Nestucca R at Cloverdale",
"11856-ORDEQ Nehalem River at Foley Road (Roy Creek Campground)")
),
checkboxGroupInput(
inputId = "river_site",
label = "Select River/Stream Sites:",
choices = c("13368-ORDEQ Nehalem River at River Mile 15.0",
"21800-ORDEQ Nestucca River at River Mile 38.57",
"22394-ORDEQ Nestucca River at first bridge ramp (upstream of Beaver)",
"23509-ORDEQ Nehalem River downstream of Humbug Creek at Lower Nehalem Road",
"29292-ORDEQ Nehalem River at Salmonberry River",
"29302-ORDEQ Nehalem River at Spruce Run Creek"),
selected = c("13368-ORDEQ Nehalem River at River Mile 15.0",
"21800-ORDEQ Nestucca River at River Mile 38.57")
)
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Min DO (mg/L)",
wellPanel(
tags$h3("Estuary Sites"),
plotlyOutput("mindoplot_e", height = 500),
br(),
br(),
tags$h3("River/Stream Sites"),
plotlyOutput("mindoplot_r", height = 500),
style = "background:white")
),
tabPanel("Min DO Saturation (%)",
wellPanel(
tags$h3("Estuary Sites"),
plotlyOutput("mindosplot_e", height = 500),
br(),
br(),
tags$h3("River/Stream Sites"),
plotlyOutput("mindosplot_r", height = 500),
style = "background: white")
)
)
)
)
),
# __1.2.3 Boxplots ----
tabPanel("Boxplots",
br(),
sidebarLayout(
sidebarPanel(
width = 3,
selectInput("boxplot",
"Select x-axis:",
choices = c(
"Site" = "StationDes",
"Season" = "season",
"Year" = "year"
)
),
selectInput("boxplotgrp",
"Select color:",
choices = c(
"Site" = "StationDes",
"Season" = "season",
"Year" = "year"
)
),
pickerInput("boxplotsites",
"Select sites:",
choices = list(
Estuarine =
c("10523-ORDEQ Nestucca R at Cloverdale",
"11856-ORDEQ Nehalem River at Foley Road (Roy Creek Campground)",
"13421-ORDEQ Wilson River at Hwy 101",
"13428-ORDEQ Dougherty Slough at Hwy 101",
"13429-ORDEQ Dougherty Slough at Wilson River Loop Road (Tillamook)",
"13430-ORDEQ Hoquarten Slough at Hwy 101 (Tillamook)",
"13431-ORDEQ Trask River at Netarts Road (Hwy. 6)",
"34440-ORDEQ Hall Slough at Goodspeed Road (Tillamook, OR)",
"Sand Lake Estuary Beltz Property Upper Channel",
"Sand Lake Estuary Beltz Property at Tigegate on inside of Dike",
"Sand Lake Estuary Beltz Property at Tigegate on outside of Dike",
"Sand Lake Estuary Beltz Property Reference Slough in Lower Bay",
"Sand Lake Estuary Channel Below Beaver Dam",
"Sand Lake Estuary Side Channel above Beaver Dam",
"Sand Lake Estuary North (SandBeach Entrance)",
"Sand Lake Estuary Central (Whalen Isand Br)",
"Sand Lake Estuary South (Sitka Channel)"),
"River/Stream" =
c("13368-ORDEQ Nehalem River at River Mile 15.0",
"21800-ORDEQ Nestucca River at River Mile 38.57",
"22394-ORDEQ Nestucca River at first bridge ramp (upstream of Beaver)",
"23509-ORDEQ Nehalem River downstream of Humbug Creek at Lower Nehalem Road",
"29292-ORDEQ Nehalem River at Salmonberry River",
"29302-ORDEQ Nehalem River at Spruce Run Creek")
),
selected = c("10523-ORDEQ Nestucca R at Cloverdale",
"13368-ORDEQ Nehalem River at River Mile 15.0"),
multiple = TRUE
)),
mainPanel(
width = 9,
wellPanel(
style = "background: white",
plotlyOutput("summaryboxplot"),
br(),
br(),
plotlyOutput("summaryboxplot_s")
)
)
)
)
)
),
# 1.3 Display continuous data ----
tabPanel("Display Continuous Data",
fluidPage(
tabsetPanel(
# __1.3.1 Plots ----
tabPanel("Plots",
sidebarLayout(
sidebarPanel(
width = 3,
pickerInput(inputId = "station_selection",
label = h3("Select sites:"),
choices = list(
Estuarine =
c("10523-ORDEQ Nestucca R at Cloverdale",
"11856-ORDEQ Nehalem River at Foley Road (Roy Creek Campground)",
"13421-ORDEQ Wilson River at Hwy 101",
"13428-ORDEQ Dougherty Slough at Hwy 101",
"13429-ORDEQ Dougherty Slough at Wilson River Loop Road (Tillamook)",
"13430-ORDEQ Hoquarten Slough at Hwy 101 (Tillamook)",
"13431-ORDEQ Trask River at Netarts Road (Hwy. 6)",
"34440-ORDEQ Hall Slough at Goodspeed Road (Tillamook, OR)",
"Sand Lake Estuary Beltz Property Upper Channel",
"Sand Lake Estuary Beltz Property at Tigegate on inside of Dike",
"Sand Lake Estuary Beltz Property at Tigegate on outside of Dike",
"Sand Lake Estuary Beltz Property Reference Slough in Lower Bay",
"Sand Lake Estuary Channel Below Beaver Dam",
"Sand Lake Estuary Side Channel above Beaver Dam",
"Sand Lake Estuary North (SandBeach Entrance)",
"Sand Lake Estuary Central (Whalen Isand Br)",
"Sand Lake Estuary South (Sitka Channel)"),
"River/Stream" =
c("13368-ORDEQ Nehalem River at River Mile 15.0",
"21800-ORDEQ Nestucca River at River Mile 38.57",
"22394-ORDEQ Nestucca River at first bridge ramp (upstream of Beaver)",
"23509-ORDEQ Nehalem River downstream of Humbug Creek at Lower Nehalem Road",
"29292-ORDEQ Nehalem River at Salmonberry River",
"29302-ORDEQ Nehalem River at Spruce Run Creek")
),
selected = c("34440-ORDEQ Hall Slough at Goodspeed Road (Tillamook, OR)"),
multiple = FALSE
),
selectInput(
inputId = "x",
label = "X-axis",
choices = c("Sample Time" = "Sample Time", # "selectInput item" = "data variable name" (both need to be "" no matter it is long name or short name)
"Temperature (\u00B0C)" = "Temperature (\u00B0C)",
"Temperature Grade" = "Temperature Grade",
"pH" = "pH",
"pH Grade" = "pH Grade",
"Specific Conductivity (\u03BCS)" = "Specific Conductivity (\u03BCS)",
"Specific Conductivity Grade" = "Specific Conductivity Grade",
"Dissolved Oxygen Grade" = "Dissolved Oxygen Grade",
"Dissolved Oxygen Saturation (%)" = "Dissolved Oxygen Saturation (%)",
"Dissolved Oxygen Saturation Grade" = "Dissolved Oxygen Saturation Grade",
"Data Source" = "Data Source"),
selected = "Sample Time" # "data variable name"
),
selectInput(
inputId = "y2",
label = "2nd y-axis",
choices = c("Sample Time" = "Sample Time",
"Temperature (\u00B0C)" = "Temperature (\u00B0C)",
"Temperature Grade" = "Temperature Grade",
"pH" = "pH",
"pH Grade" = "pH Grade",
"Specific Conductivity (\u03BCS)" = "Specific Conductivity (\u03BCS)",
"Specific Conductivity Grade" = "Specific Conductivity Grade",
"Dissolved Oxygen Grade" = "Dissolved Oxygen Grade",
"Dissolved Oxygen Saturation (%)" = "Dissolved Oxygen Saturation (%)",
"Dissolved Oxygen Saturation Grade" = "Dissolved Oxygen Saturation Grade",
"Data Source" = "Data Source"),
selected = "Temperature (\u00B0C)"
),
selectInput(
inputId = "y3",
label = "3rd y-axis",
choices = c("Sample Time" = "Sample Time",
"Temperature (\u00B0C)" = "Temperature (\u00B0C)",
"Temperature Grade" = "Temperature Grade",
"pH" = "pH",
"pH Grade" = "pH Grade",
"Specific Conductivity (\u03BCS)" = "Specific Conductivity (\u03BCS)",
"Specific Conductivity Grade" = "Specific Conductivity Grade",
"Dissolved Oxygen Grade" = "Dissolved Oxygen Grade",
"Dissolved Oxygen Saturation (%)" = "Dissolved Oxygen Saturation (%)",
"Dissolved Oxygen Saturation Grade" = "Dissolved Oxygen Saturation Grade",
"Data Source" = "Data Source"),
selected = "Specific Conductivity (?S)"
),
selectInput(
inputId = "y4",
label = "4th y-axis",
choices = c("Sample Time" = "Sample Time",
"Temperature (\u00B0C)" = "Temperature (\u00B0C)",
"Temperature Grade" = "Temperature Grade",
"pH" = "pH",
"pH Grade" = "pH Grade",
"Specific Conductivity (\u03BCS)" = "Specific Conductivity (\u03BCS)",
"Specific Conductivity Grade" = "Specific Conductivity Grade",
"Dissolved Oxygen Grade" = "Dissolved Oxygen Grade",
"Dissolved Oxygen Saturation (%)" = "Dissolved Oxygen Saturation (%)",
"Dissolved Oxygen Saturation Grade" = "Dissolved Oxygen Saturation Grade",
"Data Source" = "Data Source"),
selected = "pH"
),
dateRangeInput(
inputId = "daterange",
label = "Select dates:",
start = min(dta1$Date),
end = max(dta1$Date),
min = min(dta1$Date),
max = max(dta1$Date),
separator = "to",
format = "yyyy-mm-dd",
startview = "year",
weekstart = 0
)
),
mainPanel(
plotlyOutput("subplot", height = 800)
)
)
),
# __1.3.2 Table ----
tabPanel("Table",
wellPanel(
h3("Table of Plot Data"),
DT::dataTableOutput("plottable"),
style = "background: white"
)
)
)
)
)
)
) # UI END ----
# 2. SERVER ----
server <- function(input,output,session){
# 2.1 Leaflet map ----
meets$pctbin <- factor(meets$pctbin,levels = c("All samples meet criteria",
"More than 50% samples meet criteria",
"Less than 50% samples meet criteria",
"No samples meet criteria"))
pctcolor <- colorFactor(palette = c("blue","green","orange","red"), domain = meets$pctbin)
output$map <- renderLeaflet({
leaflet() %>%
addProviderTiles("Esri.WorldImagery",group = "Esir Satellite Map") %>%
addProviderTiles("OpenTopoMap", group = "Open Topo Map") %>%
addProviderTiles("CartoDB", group = "Carto Map") %>%
addLayersControl(baseGroups = c("Esir Satellite Map","Open Topo Map","Carto Map")) %>%
addCircleMarkers(data = s,
lat = ~ Lat,
lng = ~ Long,
color = ~ pctcolor(pctbin),
radius = ~ ((n.x)^(3/9)),
fillOpacity = 0.5,
label = ~ paste0("Station ID:", MLocID, " ", `Station Description`),
labelOptions = labelOptions(textOnly = FALSE),
layerId = s$`Station Description`) %>%
addLegend("bottomright",
pal = pctcolor,
values = meets$pctbin,
title = "Note:<br>Piont/Site size represents sample size<br><br>Color Legend") %>%
addResetMapButton() %>%
addFullscreenControl(pseudoFullscreen = TRUE)
})
# 2.2 Map table and info ----
maptable <- reactive({
dta %>%
filter(`Station Description` == input$map_marker_click$id) %>%
select(input$tablecolumnselector)
})
output$table <- DT::renderDataTable({
shiny::validate(need(!is.null(input$map_marker_click$id),
"Click on a station on the map to view data.",
br()))
DT::datatable(
data = maptable(),
style = 'bootstrap',
extensions = 'Buttons',
options = list(dom = 'Bfrtilp',
pageLength = 10,
compact = TRUE,
nowrap = TRUE,
scorllX = TRUE,
buttons = list('print',
list(extend = 'collection',
buttons = c('csv','excel','pdf'),
text = 'Download')
)),
rownames = FALSE,
filter = 'bottom'
) %>%
DT::formatDate("Sample Time","toLocaleString")
}, server = FALSE)
output$youhavechosen <- renderUI({
req(input$map_marker_click$id)
d <- s %>%
filter(`Station Description` == input$map_marker_click$id)
HTML(paste(
tags$h4(d$'Station Description'),
hr(),
tags$h5("MLocID: ", d$MLocID),
tags$h5("Waterbody Type: ", d$Type),
tags$h5("Lat/Long: ", round(d$Lat,4),",",round(d$Long,4)),
tags$h5("River Miles: ", round(d$RiverMile, 2)),
tags$h5("Spawn Dates: ", d$Spawn_dates),
tags$h5("Number of Samples: ", scales::comma(d$n.x)),
tags$h5("Percent of all samples meeting criteria: ", round(d$pctmeets*100),"%"),
tags$br(),
tags$br(),
tags$h5("Click and drag in the figure to zoom. Double click to zoom out.")
)
)
})
output$samplect <- renderPlotly({
shiny::validate(need(!is.null(input$map_marker_click$id),
"Click on a station on the map to view data.",
br()))
dta1 %>%
filter(StationDes == input$map_marker_click$id) %>%
group_by(month = floor_date(datetime,"month")) %>%
mutate(year = floor_date(datetime,"year")) %>%
summarize(n_samples = n()) %>%
plot_ly(x = ~ month,
y = ~ n_samples,
type = "bar") %>%
layout(yaxis = list(title = "Sample Counts"),
xaxis = list(title = "Month",
range = c(min(dta1$datetime),max(dta1$datetime))))
})
# 2.3 Sample summary plots ----
#ss <- reactive({
# dta1 %>%
# select(MLocID, StationDes,datetime,in_spawn,DO_lim,DO_sat_lim,DO_status) %>%
# group_by(month = floor_date(datetime,"month")) %>%
# group_by(MLocID,StationDes,month,in_spawn,DO_lim,DO_sat_lim,DO_status) %>%
# summarise(n=n()) %>%
# ungroup() %>%
# spread(DO_status,n,fill = 0) %>%
# rename(over = "Meets criteria",
# under = "Excursion") %>%
# mutate(month = as.Date(month),
# Spawning = dplyr::recode(as.factor(in_spawn),
# "TRUE" = "In spawning",
# "FALSE" = "Not in spawning"),
# `DO Limit` = dplyr::recode_factor(DO_lim,
# "6.5" = "6.5 mg/L (Estuarine)",
# "8" = "8 mg/L or 90% (Cold Water - Aquatic Life)",
# "11" = "11 mg/L or 95% (Spawning)"))
#})
ss <- reactive({
dta %>%
select(MLocID, `Station Description`,`Sample Time`,`During Spawning`,`DO Criteria`,`DO Saturation Criteria`,`DO Status`) %>%
group_by(month = floor_date(`Sample Time`,"month")) %>%
group_by(MLocID, `Station Description`,month,`During Spawning`,`DO Criteria`,`DO Saturation Criteria`,`DO Status`) %>%
summarise(n=n()) %>%
ungroup() %>%
spread(`DO Status`,n,fill = 0) %>%
rename(over = "Meets criteria",
under = "Excursion") %>%
mutate(month = as.Date(month),
Spawning = dplyr::recode(as.factor(`During Spawning`),
"TRUE" = "In spawning",
"FALSE" = "Not in spawning"),
`DO Limit` = dplyr::recode_factor(`DO Criteria`,
"6.5" = "6.5 mg/L (Estuarine)",
"8" = "8 mg/L or 90% (Cold Water - Aquatic Life)",
"11" = "11 mg/L or 95% (Spawning)"))
})
output$summaryplot <- renderPlotly({
plot_ly(ss(), x = ~get(input$plottype)) %>%
add_trace(y = ~over,
name = 'Meets criteria',
marker = list(color="blue"),
type = 'bar') %>%
add_trace(y = ~under,
name = 'Excursion',
marker = list(color="red"),
type = 'bar') %>%
layout(yaxis = list(title = 'Sample Counts'),
xaxis = list(title = tools::toTitleCase(input$plottype)))
})
# output$site <- renderTable({
# sites[,c(1,2)]
# })
# 2.4 Min DO plots ----
# set colors
pal <- viridis_pal(option = "D",direction = -1)(23)
pal <- setNames(pal,unique(dta1$Site))
# col <- colorRampPalette(brewer.pal(9,"Set3"))(14)
# sitecol <- viridis_pal(option = "D")(14)
# marginlist <- list(
# l = 60,
# r = 20,
# b = 50,
# t = 20
# )
#
wdi_e <- reactive({
dta1 %>%
select(MLocID,Site,StationDes,datetime,do) %>%
group_by(MLocID, Site, StationDes, month = floor_date(datetime,"month")) %>%
filter(Site %in% input$estuary_site) %>%
summarize(min = min(do, na.rm = TRUE))
})
output$mindoplot_e <- renderPlotly({
req(wdi_e())
plot_ly(wdi_e(),
x = ~month,
y = ~min,
text = ~paste("Site:", Site),
color = ~Site,
colors = pal,
name = ~StationDes,
mode = "markers",
type = "scatter",
marker = list(size = 10,alpha = 0.8)) %>%
layout(title = list(text = "",x = 0),
showlegend = T,
legend = list(orientation = "h",
x=0),
xaxis = list(title = "",
range = c("2007-01-01", "2017-01-31")),
yaxis = list(title = "Dissolved Oxygen (mg/L)",
range = c(-1, 13)),
annotations = list(text = "6.5 mg/L (Estuarine)",
x = "2016-05-01",
y = 6.5,
showarrow = TRUE)) %>%
add_segments(x ="2007-01-01",
xend = "2017-01-31",
y = 6.5,
yend = 6.5,
color = I("red"),
line = list(dash = "dash"),
marker = list(size = 0),
showlegend = FALSE)
})
wdi_r <- reactive({
dta1 %>%
select(MLocID,Site,StationDes,datetime,do,DO_lim,in_spawn) %>%
group_by(MLocID, Site, StationDes, DO_lim, in_spawn, month = floor_date(datetime,"month")) %>%
filter(Site %in% input$river_site) %>%
summarize(min = min(do, na.rm = TRUE)) %>%
mutate(Spawning = dplyr::recode(as.factor(in_spawn),
"TRUE" = "In spawning",
"FALSE" = "Not in spawning"))
})
output$mindoplot_r <- renderPlotly({
plot_ly(wdi_r(),
x = ~month,
y = ~min,
text = ~paste("Site:", Site, " (",Spawning,")"),
color = ~Site,
colors = pal,
name = ~paste(StationDes,Spawning,sep="\n"),
mode = "markers",
type = "scatter",
marker = list(size = 10,alpha = 0.8),
symbol = ~in_spawn,
symbols = c("circle","x")) %>%
layout(title = list(text = "",x = 0),
showlegend = T,
legend = list(orientation = "h",
x=0),
xaxis = list(title = "",
range = c("2007-01-01", "2017-01-31")),
yaxis = list(title = "Dissolved Oxygen (mg/L)",
range = c(-1, 13))) %>%
add_segments(x ="2007-01-01",
xend = "2017-01-31",
y = 11,
yend = 11,
color = I("red"),
line = list(dash = "dash"),
marker = list(size = 0),
showlegend = FALSE) %>%
add_segments(x ="2007-01-01",
xend = "2017-01-31",
y = 8,
yend = 8,
color = I("red"),
line = list(dash = "dash"),
marker = list(size = 0),
showlegend = FALSE) %>%
add_annotations(x = "2016-05-01",
y = 11,
xref = "x",
yref = "y",
text = "11 mg/L (Spawning)",
showarrow = TRUE) %>%
add_annotations(x = "2016-05-01",
y = 8,
xref = "x",
yref = "y",
text = "8 mg/L\n(Cold Water - Aquatic Life)",
showarrow = TRUE)
})
# 2.5 Min DO Sat plots ----
wdis_e <- reactive({
dta1 %>%
select(MLocID,Site,StationDes,datetime,do_sat_cor) %>%
group_by(MLocID, Site, StationDes, month = floor_date(datetime,"month")) %>%
filter(Site %in% input$estuary_site) %>%
summarize(min = min(do_sat_cor, na.rm = TRUE))
})
output$mindosplot_e <- renderPlotly({
req(wdis_e())
plot_ly(wdis_e(),
x = ~month,
y = ~min,
text = ~paste("Site:", Site),
color = ~Site,
colors = pal,
name = ~StationDes,
mode = "markers",
type = "scatter",
marker = list(size = 10,alpha = 0.8)) %>%
layout(title = list(text = "",x = 0),
showlegend = T,
legend = list(orientation = "h",
x=0),
xaxis = list(title = "",
range = c("2007-01-01", "2017-01-31")),
yaxis = list(title = "Dissolved Oxygen Saturation (%)",
range = c(0,110))
)
})
wdis_r <- reactive({
dta1 %>%
select(MLocID,Site,StationDes,datetime,do_sat_cor,DO_lim,in_spawn) %>%
group_by(MLocID, Site, StationDes, DO_lim, in_spawn, month = floor_date(datetime,"month")) %>%
filter(Site %in% input$river_site) %>%
summarize(min = min(do_sat_cor, na.rm = TRUE)) %>%
mutate(Spawning = dplyr::recode(as.factor(in_spawn),
"TRUE" = "In spawning",
"FALSE" = "Not in spawning"))
})
output$mindosplot_r <- renderPlotly({
req(wdis_r())
plot_ly(wdis_r(),
x = ~month,
y = ~min,
text = ~paste("Site:", Site, " (",Spawning,")"),
color = ~Site,
colors = pal,
name = ~paste(StationDes,Spawning,sep="\n"),
mode = "markers",
type = "scatter",
marker = list(size = 10,alpha = 0.8),
symbol = ~in_spawn,
symbols = c("circle","x")) %>%
layout(title = list(text = "",x = 0),
showlegend = T,
legend = list(orientation = "h",
x=0),
xaxis = list(title = "",
range = c("2007-01-01", "2017-01-31")),
yaxis = list(title = "Dissolved Oxygen Saturation (%)",
range = c(0, 130))) %>%
add_segments(x ="2007-01-01",
xend = "2017-01-31",
y = 95,
yend = 95,
color = I("red"),
line = list(dash = "dash"),
marker = list(size = 0),
showlegend = FALSE) %>%
add_segments(x ="2007-01-01",
xend = "2017-01-31",
y = 90,
yend = 90,
color = I("red"),
line = list(dash = "dash"),
marker = list(size = 0),
showlegend = FALSE) %>%
add_annotations(x = "2016-05-01",
y = 95,
text = "95% (Spawning)",
showarrow = T) %>%
add_annotations(x = "2015-10-01",
y = 90,
yshift = -10,
text = "90% (Cold Water - Aquatic Life)",
showarrow = F)
})
# 2.6 Boxplots ----
boxplotdata <- reactive({
dta1 %>%
mutate(month = floor_date(datetime,"month")) %>%
mutate(season = factor(month.abb[month(month)],
levels = c("May","Jun","Jul","Aug", "Oct","Nov"))) %>%
mutate(year = factor(year(floor_date(datetime,"year")))) %>%
filter(Site %in% input$boxplotsites)
})
output$summaryboxplot <- renderPlotly({
plot_ly(boxplotdata(),
x = ~get(input$boxplot),
y = ~do,
color = ~get(input$boxplotgrp),
# colors = viridis_pal(option = "D")(6),
type = "box") %>%
layout(boxmode = 'group',
xaxis = list(title = tools::toTitleCase(input$boxplot)),
yaxis = list(title = "Dissolved Oxygen (mg/L)"))
})
output$summaryboxplot_s <- renderPlotly({
plot_ly(boxplotdata(),
x = ~get(input$boxplot),
y = ~do_sat_cor,
color = ~get(input$boxplotgrp),
# colors = viridis_pal(option = "D")(6),
type = "box") %>%
layout(boxmode = 'group',
xaxis = list(title = tools::toTitleCase(input$boxplot)),
yaxis = list(title = "Dissolved Oxygen Saturation (%)"))
})
# 2.7 Display continuous data: Plots ----
do_col <- setNames(c("blue","red"),unique(dta$`DO Status`))
stations_subset <- reactive({
dta %>%
filter(Site == input$station_selection) %>%
filter(Date >= input$daterange[1],
Date <= input$daterange[2])
})
output$subplot <- renderPlotly({
a <- plot_ly(stations_subset(),
x = ~get(input$x),
y = ~`Dissolved Oxygen (mg/L)`,
type = "scatter",
mode = "markers",
color = ~`DO Status`,
colors = do_col,
showlegend = TRUE) %>%
layout(yaxis = list(title = "Dissolved Oxygen (mg/L)"),
xaxis = list(showline = TRUE, zeroline = FALSE))
b <- plot_ly(stations_subset(),
x = ~get(input$x),
y = ~get(input$y2),
type = "scatter",
mode = "markers",
marker = list(color = "black"),
showlegend = FALSE) %>%
layout(yaxis = list(title = toTitleCase(input$y2)),
xaxis = list(showline = TRUE, zeroline = FALSE))
c <- plot_ly(stations_subset(),
x = ~get(input$x),
y = ~get(input$y3),
type = "scatter",
mode = "markers",
marker = list(color = "green"),
showlegend = FALSE) %>%
layout(yaxis = list(title = toTitleCase(input$y3)),
xaxis = list(showline = TRUE, zeroline = FALSE))
d <- plot_ly(stations_subset(),
x = ~get(input$x),
y = ~get(input$y4),
type = "scatter",
mode = "markers",
marker = list(color = "purple"),
showlegend = FALSE) %>%
layout(yaxis = list(title = toTitleCase(input$y4)),
xaxis = list(showline = TRUE, zeroline = FALSE))
sp <- subplot(a,b,c,d, nrows = 4, shareX = TRUE, titleY = TRUE)
sp %>%
layout(
xaxis = list(
title = toTitleCase(input$x),
rangeselector = list()
)
)
})
# 2.8 Display continuous data: Table ----
output$plottable <- DT::renderDataTable({
stations_subset_tb <- reactive({
stations_subset() %>%
select(MLocID, `Station Description`, `Sample Time`, `Dissolved Oxygen (mg/L)`, `Dissolved Oxygen Grade`,
`Dissolved Oxygen Saturation (%)`, `Dissolved Oxygen Saturation Grade`, `DO Status`, `Temperature (°C)`,
`Temperature Grade`, pH, `pH Grade`, `Specific Conductivity (µS)`, `Specific Conductivity Grade`, `Data Source`) %>%
select(MLocID,`Station Description`, `Sample Time`, `Dissolved Oxygen (mg/L)`, input$x, input$y2, input$y3, input$y4)
})
DT::datatable(
data = stations_subset_tb(),
style = 'bootstrap',
extensions = 'Buttons',
options = list(dom = 'Bfrtilp',
pageLength = 10,
compact = TRUE,
nowrap = TRUE,
scorllX = TRUE,
buttons = list('print',
list(extend = 'collection',
buttons = c('csv','excel','pdf'),
text = 'Download')
)),
rownames = FALSE,
filter = 'top'
)
}, server = FALSE)
}
shinyApp(ui,server)