forked from yanyanyun/CEAMEC
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.r
605 lines (432 loc) · 38.2 KB
/
ui.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
#load package
library(shiny)
library(rgdal)
library(leaflet)
library(shinycssloaders)
library(shinythemes)
library(tibble)
library(unmarked)
library(DT)
library(data.table)
library(xlsx)
library(htmltools)
library(bsplus)
library(dplyr)
library(shinycssloaders)
library(rgeos)
library(shinyjs)
# ui object
ui <- navbarPage("Cost-Effective Animal Management via Environmental Capacity",
useShinyjs(),
theme = shinytheme("united"),
#Tab "Distance sampling"
navbarMenu("Field data input",
tabPanel("Distance sampling",
tags$style(".first-p{
color: SaddleBrown;
font-size: 20px;
font-weight: bold;
}"),
tags$style(".second-p{
color: black;
font-size: 14px;
font-weight: bold;
}"),
br(),
br(),
h2 ("Hierarchical distance sampling with unmarked"),
p(class = "first-p", "Survey information"),
use_bs_popover(),
a(href="https://github.com/qt37t247/CEAMEC/blob/master/distdata.csv", "See an example of survey data file", style = "color: blue;"),
fileInput(
inputId = "distdata",
label = "Upload survey data (csv file)",
accept = c(".csv")
)%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "A csv format data frame where each row is a detected individual. It must have two columns. One (named 'distance') for distances to the detected individuals and the other (named 'transect') for transect names.",
placement = "right", trigger = "hover"
)
),
a(href="https://github.com/qt37t247/CEAMEC/blob/master/covs.csv", "See an example of covariate file", style = "color: blue;"),
fileInput(
inputId = "covariates",
label = "Upload covariates (csv file)",
accept = c(".csv")
)%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "A csv format data frame of environmental variables (covariates) that vary at the site level. The number of rows must match the number of transects. The number of columns should equal to the number of covariates with one column per covariate. An additional column (named
'length') should be attached as the last column for the length of transects (in the unit of meter, put 0 if using point transects).",
placement = "right", trigger = "hover"
)
),
textInput("binsize", "Size of bin in meters", placeholder = "10", width = "70%")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "Distance data is binned into discrete distance classes with the size provided.", placement = "right", trigger = "hover"
)
),
br(),
verbatimTextOutput("summary_distsamp"),
plotOutput('Hist'),
actionButton("detect", "Check detection functions", class = "btn btn-primary"),
br(),
fluidRow(
column(5,
dataTableOutput("detect_fun")
)
),
br(),
p(class = "first-p", "Modelling with covariates"),
textInput("det", "Detection covariates (comma delimited)", placeholder = "FI, FI+LU", width = "70%")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "List covariates and combinations of covariates to model detection (comma delimited). A combination of covariates is written as the names of covariates connected with '+'. Consider a non-interactive run if many combinations are tested, otherwise, very time-consuming.", placement = "right", trigger = "hover"
)
),
hidden(h5("Error: input does not match available covariates' names",
id = "message_det",
style = "font-weight:bold;color:red;")),
textInput("state", "Abundance covariates (comma delimited)", placeholder = "FI+LU, FI+LU+EE+BS+OP+V", width = "70%")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "List covariates and combinations of covariates to model abundance (comma delimited). A combination of covariates is written as the names of covariates connected with '+'. Consider a non-interactive run if many combinations are tested, otherwise, very time-consuming.", placement = "right", trigger = "hover"
)
),
hidden(h5("Error: input does not match available covariates' names",
id = "message_state",
style = "font-weight:bold;color:red;")),
selectInput("keyfun", "Detection function", c("","halfnorm", "hazard", "uniform", "exp"), selected = NULL)%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "You could choose based on the table above if you ran check detection functions (normally the one with the lowest AIC)", placement = "right", trigger = "hover"
)
),
actionButton("ModelCovs_distsamp", "Start computing models", class = "btn btn-primary"),
br(),
br(),
p(class = "first-p", "Models with covariates"),
fluidRow(
column(5,
dataTableOutput("covmodels_distsamp")
)
),
uiOutput("bestmodels_distsamp"),
textInput("nsims_distsamp", "Number of replicates for parametric bootstrapping", placeholder = "25", width = "70%")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "Number of bootstrap replicates (must be an integer) to check the adequacy of model fit. It can be time-consuming (>1 hour) if a large number (>100) is chosen.", placement = "right", trigger = "hover"
)
),
actionButton("Parboot_distsamp", "Re-fit model", class = "btn btn-primary"),
fluidRow(
column(5,
dataTableOutput("parboot_distsamp")
)
),
br(),
uiOutput("Managerables_distsamp"),
uiOutput("continue_distsamp"),
br()
),#End Tab "Distance sampling"
#Tab "Repeated count"
tabPanel("Repeated count",
br(),
br(),
h2 ("N-mixture model with unmarked"),
p(class = "first-p", "Survey information"),
a(href="https://github.com/qt37t247/CEAMEC/blob/master/mld_pcount.csv", "See an example of survey data file", style = "color: blue;"),
fileInput(
inputId = "pcdata",
label = "Upload survey data (csv file)",
accept = c(".csv")
)%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "A csv format data frame of the repeated count data with observation and site covariates appended. A transect per row. Columns contain counts (one session per column), observation covariates (one session per column) and site covariates (one covariate per column). Different sessions can be identified with '.#' (e.g. '.1','.2','.3') in the column names.", placement = "right", trigger = "hover"
)
),
br(),
uiOutput("countcol"),
uiOutput("sitecol"),
uiOutput("obscol"),
textInput("area_pcount", "Area of each survey site in hectares", placeholder = "1")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "Normally to be the size of the transect. But if using traps, you may need to estimate the area the trap may cover", placement = "right", trigger = "hover"
)
),
verbatimTextOutput("summary_pcount"),
actionButton("mixture_in", "Check abundance distribution", class = "btn btn-primary"),
br(),
fluidRow(
column(5,
dataTableOutput("mixture_fun")
)
),
br(),
p(class = "first-p", "Modelling with covariates"),
textInput("det_pc", "Detection covariates (comma delimited)", placeholder = "1, date, ivel+date", width = "70%")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "List covariates and combinations of covariates (can be either/both observation and site covariates) to model detection (comma delimited). A combination of covariates is written as the names of covariates connected with '+'. Consider a non-interactive run if many combinations are tested, otherwise, very time-consuming.", placement = "right", trigger = "hover"
)
),
hidden(h5("Error: input does not match available covariates' names",
id = "message_det_pc",
style = "font-weight:bold;color:red;")),
textInput("state_pc", "Abundance covariates (comma delimited)", placeholder = "1, elev, length+forest", width = "70%")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "List covariates and combinations of covariates (site covariates only) to model abundance (comma delimited). A combination of covariates is written as the names of covariates connected with '+'. Consider a non-interactive run if many combinations are tested, otherwise, very time-consuming.", placement = "right", trigger = "hover"
)
),
hidden(h5("Error: input does not match available covariates' names (site covariates only)",
id = "message_state_pc",
style = "font-weight:bold;color:red;")),
selectInput("mixture", "Latent abundance distribution", c("", "Poisson (P)" = "P", "Negative binomial (NB)" = "NB", "Zero-inflated Poisson random variable (ZIP)" = "ZIP"), selected = NULL)%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "You could choose based on the table above if you ran check abundance distribution (normally the one with the lowest AIC)", placement = "right", trigger = "hover"
)
),
actionButton("ModelCovs_pcount", "Start computing models", class = "btn btn-primary"),
br(),
br(),
p(class = "first-p", "Models with covariates"),
fluidRow(
column(5,
dataTableOutput("covmodels_pcount")
)
),
uiOutput("bestmodels_pcount"),
textInput("nsims_pcount", "Number of replicates for parametric bootstrapping", placeholder = "25", width = "70%")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "Number of bootstrap replicates (must be an integer) to check the adequacy of model fit. It can be time-consuming (>1 hour) if a large number (>100) is chosen.", placement = "right", trigger = "hover"
)
),
actionButton("Parboot_pcount", "Re-fit model", class = "btn btn-primary"),
fluidRow(
column(5,
dataTableOutput("parboot_pcount")
)
),
br(),
uiOutput("Managerables_pcount"),
uiOutput("continue_pcount"),
br()
),
#End Tab "Repeated count"
#Tab "Removal sampling or double observer sampling"
tabPanel("Removal sampling or double observer sampling",
br(),
br(),
h2 ("Multinomial-Poisson Mixture model with unmarked"),
p(class = "first-p", "Survey information"),
a(href="https://github.com/qt37t247/CEAMEC/blob/master/oven_removal.csv", "See an example of removal sampling survey data file", style = "color: blue;"),
br(),
a(href="https://github.com/qt37t247/CEAMEC/blob/master/fake_double.csv", "See an example of double observer sampling survey data file", style = "color: blue;"),
fileInput(
inputId = "mndata",
label = "Upload survey data (csv file)",
accept = c(".csv")
)%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "A csv format data frame of the count data with observation and site covariates appended. A transect per row. Columns contain counts (one session per column), observation covariates (one session per column) and site covariates (one covariate per column). Different sessions can be identified with '.#' (e.g. '.1','.2','.3') in the column names.", placement = "right", trigger = "hover"
)
),
uiOutput("countcolm"),
uiOutput("sitecolm"),
uiOutput("obscolm"),
selectInput("mntype", "Survey type", c("", "Removal sampling" = "removal", "Standard double observer sampling" = "double", "Dependent double observer sampling" = "depDouble"), selected = NULL),
textInput("area_mn", "Area of each survey site in hectares", placeholder = "1")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "Normally to be the size of the transect. But if using traps, you may need to estimate the area that the trap may cover", placement = "right", trigger = "hover"
)
),
verbatimTextOutput("summary_mn"),
br(),
p(class = "first-p", "Modelling with covariates"),
textInput("det_mn", "Detection covariates (comma delimited)", placeholder = "1,obsA,obsB,obsA+obsB", width = "70%")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "List covariates and combinations of covariates (can be either/both observation and site covariates) to model detection (comma delimited). A combination of covariates is written as the names of covariates connected with '+'. Consider a non-interactive run if many combinations are tested, otherwise, very time-consuming.", placement = "right", trigger = "hover"
)
),
hidden(h5("Error: input does not match available covariates' names",
id = "message_det_mn",
style = "font-weight:bold;color:red;")),
textInput("state_mn", "Abundance covariates (comma delimited)", placeholder = "1,covA,covB,covA+covB", width = "70%")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "List covariates and combinations of covariates (site covairates only) to model abundance (comma delimited). A combination of covariates is written as the names of covariates connected with '+'. Consider a non-interactive run if many combinations are tested, otherwise, very time-consuming.", placement = "right", trigger = "hover"
)
),
hidden(h5("Error: input does not match available covariates' names (site covariates only)",
id = "message_state_mn",
style = "font-weight:bold;color:red;")),
actionButton("ModelCovs_mn", "Start computing models", class = "btn btn-primary"),
br(),
br(),
p(class = "first-p", "Models with covariates"),
fluidRow(
column(5,
dataTableOutput("covmodels_mn")
)
),
uiOutput("bestmodels_mn"),
textInput("nsims_mn", "Number of replicates for parametric bootstrapping", placeholder = "25", width = "70%")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "Number of bootstrap replicates (must be an integer) to check the adequacy of model fit. It can be time-consuming (>1 hour) if a large number (>100) is chosen.", placement = "right", trigger = "hover"
)
),
actionButton("Parboot_mn", "Re-fit model", class = "btn btn-primary"),
fluidRow(
column(5,
dataTableOutput("parboot_mn")
)
),
br(),
uiOutput("Managerables_mn"),
uiOutput("continue_mn"),
br()
)
),
#End Tab "Removal sampling or double observer sampling"
#Tab "CEAMEC"
tabPanel("CEAMEC",
br(),
br(),
h2 ("Cost-Effective Animal Management via Environmental Capacity"),
textInput("gr", "Growth rate (per month)", placeholder = "0.02775")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "The growth rate can be estimated from reproductive experiments or field observations. If using the annual growth rate, please divide by 12.", placement = "right", trigger = "hover"
)
),
textInput("mth", "Achieve target in____months", placeholder = "24")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "Length in months for the period of management", placement = "right", trigger = "hover"
)
),
a(href="https://github.com/qt37t247/CEAMEC/blob/master/newdata.csv", "See an example of newdata file", style = "color: blue;"),
fileInput(
inputId = "newdata",
label = "Upload covariates for prediction (csv file)",
accept = c(".csv")
)%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "A csv format data frame containing environmental variable of the rasterized area of study. Each row represents each cell in the rasterized study area with the cell ID indicated in the first column. All determinant covariates should be included with one covariate per column starting from the second column.", placement = "right", trigger = "hover"
)
),
flowLayout(
textInput("le", "Longitude (E)", placeholder = "104.0364"),
textInput("lw", "Longitude (W)", placeholder = "103.6051"),
textInput("ln", "Latitude (N)", placeholder = "1.472969"),
textInput("ls", "Latitude (S)", placeholder = "1.219747"),
textInput("nrows", "Number of rows", placeholder = "56"),
textInput("ncols", "Number of columns", placeholder = "96")
),
uiOutput("clickmap"),
leafletOutput(outputId = "map") %>% withSpinner(color="#DD4814"),
br(),
br(),
p(class = "second-p", "Average per hectare in selected cells"),
verbatimTextOutput("aver", placeholder = TRUE),
p(class = "second-p", "Background density"),
verbatimTextOutput("mini", placeholder = TRUE),
textInput("expct", "Density must be under____ per ha", placeholder = "3")%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "Don't set this value lower than the background density (see above). Background density of each cell can be seen with mouse hover over.", placement = "right", trigger = "hover"
)
),
hidden(h5("Error: target density too low! Please set a number higher than the background density",
id = "message_expect",
style = "font-weight:bold;color:red;")),
a(href="https://github.com/qt37t247/CEAMEC/blob/master/cost.csv", "See an example of cost file", style = "color: blue;"),
fileInput(
inputId = "cost",
label = "Upload cost (csv file)",
multiple = TRUE,
accept = c(".csv")
)%>%
shinyInput_label_embed(
shiny_iconlink() %>%
bs_embed_popover(
content = "A csv format data frame with one covariate to be managed per row and one of the four unit costs per column (in the order of a, b, c, d).", placement = "right", trigger = "hover"
)
),
hidden(h5("Error: covariates' names in the file do not match selected covariates to be managed",
id = "message_costcov",
style = "font-weight:bold;color:red;")),
hidden(h5("Error: non-numeric items in columns 2 to 5, please check the input file",
id = "message_costnum",
style = "font-weight:bold;color:red;")),
actionButton("calculate", "Submit", class = "btn btn-primary"),
br(),
br(),
p(class = "second-p", "Minimum cost to reach the management target"),
verbatimTextOutput("sum_v", placeholder = TRUE),
br(),
br(),
p(class = "second-p", "Optimalized management suggestion in a map:"),
downloadButton("downloadMap",label = "Save as kml", class = "btn btn-primary"),
br(),
br(),
p(class = "second-p", "Summary and per cell management suggestions:"),
downloadButton("downloadPer",label = "Save as excel", class = "btn btn-primary"),
br(),
br(),
br()
),
#End Tab "CEAMEC"
#Tab "Help"
tabPanel("Help",
br(),
br(),
br(),
a(href="https://youtu.be/gWALmOzZHJc", "1. I want to watch a video tutorial.", style = "font-size:25px;"),
br(),
a(href="https://github.com/qt37t247/CEAMEC/blob/master/User%20Manual.pdf", "2. I want to read the user manual.", style = "font-size:25px;"),
br(),
a(href="https://cran.r-project.org/web/packages/unmarked/index.html", "3. I want to know more about hierarchical modelling and unmarked.", style = "font-size:25px;"),
br(),
a(href="https://github.com/qt37t247/CEAMEC", "4. I want to report an issue.", style = "font-size:25px;"),
br(),
a(href="https://github.com/qt37t247/CEAMEC/blob/master/capacity.r", "5. My analysis is massive, I want script for non-interactive run with high-performance computer.", style = "font-size:25px;"),
br()
),
#End Tab "Help"
position = c("fixed-top")
)#end UI