-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
638 lines (477 loc) · 14.3 KB
/
index.Rmd
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
---
title: "CRITICAL COASTAL HABITAT ASSESSMENT"
output:
flexdashboard::flex_dashboard:
logo: www/tarponlogo.png
social: menu
source_code: "https://github.com/tbep-tech/ccha-workflow"
runtime: shiny
css: styles.css
---
```{r setup, include=F}
knitr::opts_chunk$set(echo = F, warning = F, message = F)
library(here)
library(ggplot2)
library(tidyr)
library(dplyr)
library(ggridges)
library(reactable)
library(shiny)
library(lubridate)
library(stringr)
library(forcats)
library(htmltools)
library(htmlwidgets)
library(shinyWidgets)
library(plotly)
library(mapview)
library(leaflet)
library(leafem)
source(here('R/funcs.R'))
load(file = here('data/vegdat.RData'))
load(file = here('data/treedat.RData'))
load(file = here('data/tranloc.RData'))
vegdat <- vegdat %>%
filter(sample != 2)
thm <- theme_minimal(base_size = 16) +
theme(
panel.grid.minor = element_blank()
)
# initial options
sitopt <- unique(vegdat$site)
sppopt <- unique(vegdat$species) %>%
sort %>%
.[!. %in% c('Boardwalk', 'none/detritus', 'Open Water', 'Unknown')]
# # style file
# styles <- readLines('https://raw.githubusercontent.com/tbep-tech/css-styling/master/styles.css')
# writeLines(styles, 'styles.css')
bsmap <- mapview(tranloc, homebutton = F, legend = F, layer.name = 'Transects', alpha = 0) %>%
.@map %>%
addPolylines(
data = tranloc,
stroke = T,
color = 'blue',
fillColor = "blue",
fill = T,
weight = 20,
opacity = 0.5,
fillOpacity = 0.5
) %>%
addStaticLabels(
data = tranloc,
label = tranloc$site,
direction = 'top',
textsize = '15px',
offset = c(0, 1)
)
```
```{r reactives}
# map site selection
bsmap1 <- leafletProxy('bsmap1')
observeEvent(input$sitsel1, {
# input
sitsel1 <- input$sitsel1
toadd <- tranloc %>%
filter(site %in% sitsel1)
bsmap1 <- bsmap1 %>%
removeShape(layerId = 'sitsel') %>%
addPolylines(
data = toadd,
layerId = 'sitsel',
stroke = T,
color = 'red',
fillColor = 'red',
fill = T,
weight = 20,
opacity = 0.8,
fillOpacity = 0.8
)
})
# year by site/zone
sitplo1 <- reactive({
# input
sitsel1 <- isolate(input$sitsel1)
zonsel1 <- input$zonsel1
out <- sitezonedst_plo1(vegdat, site = sitsel1, zonefct = zonsel1, thm)
return(out)
})
# distance by year/site
sitplo2 <- reactive({
# input
sitsel1 <- isolate(input$sitsel1)
zonsel1 <- input$zonsel1
req(zonsel1)
out <- sitezonedst_plo2(vegdat, site = sitsel1, zonefct = zonsel1, thm)
return(out)
})
# summary plot by species, all sites
vegplo1 <- reactive({
# input
sitsel2 <- isolate(input$sitsel2)
zonsel2 <- input$zonsel2
req(zonsel2)
out <- sitezonedst_plo3(vegdat, sitsel2, zonefct = zonsel2, thm = thm)
return(out)
})
# plot vegetation summary by site
vegplo2 <- reactive({
# input
sitsel2 <- isolate(input$sitsel2)
zonsel2 <- input$zonsel2
varsel1 <- input$varsel1
dgesel1 <- input$dgesel1
vegsel <- input$vegsel
metsel <- input$metsel
dlmtyp <- input$dlmtyp
req(zonsel2)
req(metsel)
req(vegsel)
out <- sitesum_plo(vegdat, sitsel2, delim = metsel, delimtyp = dlmtyp, vegsel = vegsel, var = varsel1, zonefct = zonsel2, dodge = dgesel1, thm = thm)
return(out)
})
# tabular vegetation summary by site
vegtab1 <- reactive({
# input
sitsel2 <- isolate(input$sitsel2)
zonsel2 <- input$zonsel2
varsel1 <- input$varsel1
req(zonsel2)
out <- sitezonesum_tab(vegdat, sitsel2, zonsel2, varsel1)
return(out)
})
# tabular vegetation summary by site
vegtabdl1 <- reactive({
# input
sitsel2 <- input$sitsel2
zonsel2 <- input$zonsel2
varsel1 <- input$varsel1
req(zonsel2)
out <- sitezonesum_fun(vegdat, sitsel2, zonsel2, varsel1)
return(out)
})
# plot tree summary by site
treeplo1 <- reactive({
# input
sitsel3 <- isolate(input$sitsel3)
zonsel3 <- input$zonsel3
varsel2 <- input$varsel2
aggsel <- input$aggsel
dgesel2 <- input$dgesel2
tresel <- input$tresel
req(zonsel3)
req(tresel)
out <- treesum_plo(treedat, sitsel3, byspecies = aggsel, zonefct = zonsel3, tresel = tresel, var = varsel2, dodge = dgesel2, thm = thm)
return(out)
})
# tabular tree summary by site
treetab1 <- reactive({
# input
sitsel3 <- isolate(input$sitsel3)
zonsel3 <- input$zonsel3
varsel2 <- input$varsel2
aggsel <- input$aggsel
req(zonsel3)
out <- treesum_tab(treedat, sitsel3, byspecies = aggsel, zonefct = zonsel3, var = varsel2)
return(out)
})
# tabular tree summary by site download
treetabdl1 <- reactive({
# input
sitsel3 <- input$sitsel3
zonsel3 <- input$zonsel3
varsel2 <- input$varsel2
aggsel <- input$aggsel
req(zonsel3)
out <- treesum_fun(treedat, sitsel3, byspecies = aggsel, zonefct = zonsel3, var = varsel2) %>%
pivot_wider(names_from = 'sample', values_from = 'val', values_fill = NA) %>%
arrange(zonefct)
return(out)
})
# summary plot by species, all sites
allplo1 <- reactive({
# input
sppsel <- input$sppsel
stesel <- input$stesel
varsel3 <- input$varsel3
req(stesel)
out <- sppsum_plo(vegdat, sppsel, var = varsel3, sitefct = stesel, thm)
return(out)
})
```
```{r download}
# download veg table
output$vegtabdl1 <- downloadHandler(
filename = function(){'vegetation_summary.csv'},
content = function(file){
# inputs
vegtabdl1 <- vegtabdl1()
write.csv(vegtabdl1, file, quote = T, row.names = F)
}
)
# download tree table
output$treetabdl1 <- downloadHandler(
filename = function(){'tree_summary.csv'},
content = function(file){
# inputs
treetabdl1 <- treetabdl1()
write.csv(treetabdl1, file, quote = T, row.names = F)
}
)
```
1 ZONES BY SITE {data-navmenu="PAGE SELECTION"}
=======================================================================
Column {data-width=200 .tabset .tabset-fade}
-----------------------------------------------------------------------
### Site selection
```{r}
column(12,
selectInput('sitsel1', 'Select site:', choices = sitopt, width = '100%')
)
column(12,
renderUI({
# input
sitsel1 <- input$sitsel1
tosel <- vegdat %>%
filter(site %in% !!sitsel1) %>%
unite('zonefct', zone, zone_name, sep = ': ') %>%
mutate(zonefct = factor(zonefct, levels = sort(unique(zonefct)))) %>%
pull(zonefct) %>%
levels
selectInput('zonsel1', 'Select zone:', choices = tosel, selectize = T, multiple = T, selected = tosel, width = '100%')
})
)
```
### About
Column {.tabset .tabset-fade data-width=700}
-----------------------------------------------------------------------
### Site Map
```{r}
output$bsmap1 <- renderLeaflet(bsmap)
leafletOutput('bsmap1')
```
### Zones by year
```{r}
output$sitplo1 <- renderPlotly(sitplo1())
plotlyOutput('sitplo1')
```
### Zone length by year
```{r}
output$sitplo2 <- renderPlotly(sitplo2())
plotlyOutput('sitplo2')
```
2 VEGETATION SURVEYS {data-navmenu="PAGE SELECTION"}
=======================================================================
Column {data-width=200 .tabset .tabset-fade}
-----------------------------------------------------------------------
### Summary options
```{r}
column(12,
selectInput('sitsel2', 'Select site:', choices = sitopt, width = '100%')
)
column(12,
renderUI({
# input
sitsel2 <- input$sitsel2
tosel <- vegdat %>%
filter(site %in% !!sitsel2) %>%
unite('zonefct', zone, zone_name, sep = ': ') %>%
mutate(zonefct = factor(zonefct, levels = sort(unique(zonefct)))) %>%
pull(zonefct) %>%
levels
selectInput('zonsel2', 'Select zone:', choices = tosel, selectize = T, multiple = T, selected = tosel, width = '100%')
})
)
column(12,
selectInput('varsel1', 'Select summary variable:', choices = list('Freq. Occ (%)' = 'fo', 'Basal cover (%)' = 'cover'), width = '100%')
)
```
### About
Column {.tabset .tabset-fade data-width=700}
-----------------------------------------------------------------------
### All species
```{r}
output$vegplo1 <- renderPlot(vegplo1())
plotOutput('vegplo1')
```
### Species summary
```{r}
output$vegplo2 <- renderPlotly(vegplo2())
fillCol(flex = c(NA, 1),
column(12,
column(2, selectInput('spptyp1', 'Select species by:', choices = c('Top n', 'Names'), width = '100%')),
column(3,
renderUI({
# inputs
spptyp1 <- input$spptyp1
sitsel2 <- input$sitsel2
if(spptyp1 == 'Names'){
tosel <- vegdat %>%
filter(site %in% sitsel2) %>%
pull(species) %>%
unique %>%
sort
sel <- tosel[1:min(length(tosel), 10)]
out <- pickerInput('vegsel', 'Select species to show:', choices = tosel, selected = sel, multiple = T,
options = list(`actions-box` = TRUE))
}
if(spptyp1 == 'Top n')
out <- sliderInput('vegsel', 'Select number of species:', min = 1, max = 30, step = 1, value = 10, width = '100%')
return(out)
})
),
column(2, selectInput('dlmtyp', 'Select meter bins by:', choices = c('Number', 'Distance'), width = '100%')),
column(3,
renderUI({
# input
dlmtyp <- input$dlmtyp
sitsel2 <- input$sitsel2
if(dlmtyp == 'Distance'){
maxv <- vegdat %>%
filter(site %in% !!sitsel2) %>%
pull(meter) %>%
max(na.rm = T) %>%
round(0)
minv <- 3
ttl <- 'Select length of meter bins:'
strval <- 25
}
if(dlmtyp == 'Number'){
minv <- 1
maxv <- 30
ttl <- 'Select number of meter bins:'
strval <- 5
}
sliderInput('metsel', ttl, min = minv, max = maxv, step = 1, value = strval, width = '100%')
})
),
column(2,
materialSwitch(inputId = 'dgesel1', label = 'Separate columns by species?', value = T, width = '100%')
)
),
plotlyOutput('vegplo2')
)
```
### Tabular summary
```{r}
output$vegtab1 <- renderReactable(vegtab1())
fillCol(flex = c(NA, 1),
downloadBttn('vegtabdl1', 'Download data', style = 'simple', block = T, color = 'success'),
reactableOutput('vegtab1')
)
```
3 TREE SURVEYS {data-navmenu="PAGE SELECTION"}
=======================================================================
Column {data-width=200 .tabset .tabset-fade}
-----------------------------------------------------------------------
### Summary options
```{r}
column(12,
selectInput('sitsel3', 'Select site:', choices = sitopt, width = '100%')
)
column(12,
renderUI({
# input
sitsel3 <- input$sitsel3
tosel <- treedat %>%
filter(site %in% !!sitsel3) %>%
unite('zonefct', zone, zone_name, sep = ': ') %>%
mutate(zonefct = factor(zonefct, levels = sort(unique(zonefct)))) %>%
pull(zonefct)
selectInput('zonsel3', 'Select zone:', choices = tosel, selectize = T, multiple = T, selected = tosel, width = '100%')
})
)
column(12,
selectInput('varsel2', 'Select summary variable:',
choices = list(
'Absolute species density (trees/m2)' = 'trees_m2',
'Absolute species density (trees/ha)'= 'trees_ha',
'Species average basal area (cm2/m2)' = 'cm2_m2',
'Species absolute cover (m2/ha)' = 'm2_ha',
'Relative cover (%)' = 'relcov_per',
'Tree height (m)' = 'tree_height'
),
width = '100%'
)
)
column(12,
materialSwitch(inputId = 'aggsel', label = 'Show results by species?', value = T, width = '100%')
)
```
### About
Column {.tabset .tabset-fade data-width=700}
-----------------------------------------------------------------------
### Species by distance
```{r}
output$treeplo1 <- renderPlotly(treeplo1())
fillCol(flex = c(NA, 1),
column(12,
column(3, selectInput('spptyp2', 'Select species by:', choices = c('Top n', 'Names'), width = '100%')),
column(3,
renderUI({
# inputs
spptyp2 <- input$spptyp2
sitsel3 <- input$sitsel3
if(spptyp2 == 'Names'){
tosel <- treedat %>%
filter(site %in% sitsel3) %>%
pull(species) %>%
unique %>%
sort
sel <- tosel[1:min(length(tosel), 10)]
out <- pickerInput('tresel', 'Select species to show:', choices = tosel, selected = sel, multiple = T,
options = list(`actions-box` = TRUE))
}
if(spptyp2 == 'Top n')
out <- sliderInput('tresel', 'Select number of species:', min = 1, max = 20, step = 1, value = 10, width = '100%')
return(out)
})
),
column(3,
materialSwitch(inputId = 'dgesel2', label = 'Separate columns by species?', value = T, width = '100%')
)
),
plotlyOutput('treeplo1')
)
```
### Tabular summary
```{r}
output$treetab1 <- renderReactable(treetab1())
fillCol(flex = c(NA, 1),
downloadBttn('treetabdl1', 'Download data', style = 'simple', block = T, color = 'success'),
reactableOutput('treetab1')
)
```
4 BETWEEN SITE COMPARISONS {data-navmenu="PAGE SELECTION"}
=======================================================================
Column {data-width=200 .tabset .tabset-fade}
-----------------------------------------------------------------------
### Summary options
Summaries are for vegetation data only.
```{r}
column(12,
selectInput('sppsel', 'Select species:', choices = sppopt, selected = 'Avicennia germinans', width = '100%')
)
column(12,
renderUI({
# input
sppsel <- input$sppsel
tosel <- vegdat %>%
filter(species %in% !!sppsel) %>%
pull(site) %>%
unique %>%
sort
selectInput('stesel', 'Select site:', choices = tosel, selectize = T, multiple = T, selected = tosel, width = '100%')
})
)
column(12,
selectInput('varsel3', 'Select summary variable:', choices = list('Freq. Occ (%)' = 'fo', 'Basal cover (%)' = 'cover'), width = '100%')
)
```
### About
Column {.tabset .tabset-fade data-width=700}
-----------------------------------------------------------------------
### Species by zone
```{r}
output$allplo1 <- renderPlotly(allplo1())
plotlyOutput('allplo1')
```