-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderUI.R
336 lines (310 loc) · 12.3 KB
/
renderUI.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
## renderUI
## persqkm
## detectorhelp
## clusterhelp
## clusteroverlap
## randomtext
## shapefile
## exclusionfile
## habitatfile
## uipopN
## uigridlines
##############################################################################
output$detectfnui <- renderUI({
if (input$detectfnbox == 'HN') x <- HTML("halfnormal")
else if (input$detectfnbox == 'EX') x <- HTML("negative exponential")
else if (input$detectfnbox == 'HR') x <- HTML("hazard rate")
else if (input$detectfnbox == 'HHN') x <- HTML("hazard halfnormal")
else if (input$detectfnbox == 'HEX') x <- HTML("hazard negative exponential")
else if (input$detectfnbox == 'HHR') x <- HTML("hazard hazard rate")
else if (input$detectfnbox == 'HVP') x <- HTML("hazard variable power")
else x <- ''
helpText(x)
})
#-----------------------------------------------------------------------------
output$secrdatadescriptionui <- renderUI({
x <- ""
if (input$secrdatabox == 'captdata')
x <- HTML("Simulated data from grid of multi-catch traps (from DENSITY)")
else if (input$secrdatabox %in% c('blackbearCH'))
x <- HTML("<i>Ursus americanus</i> DNA hair snag data from ",
"Great Smoky Mountains National Park, Tennessee")
else if (input$secrdatabox %in% c('deermouse.ESG', 'deermouse.WSG'))
x <- HTML("<i>Peromyscus maniculatus</i> Live-trapping data of V. H. Reid ",
"published as a CAPTURE example by Otis et al. (1978) Wildlife Monographs 62")
else if (input$secrdatabox == 'hornedlizardCH')
x <- HTML("Repeated searches of a quadrat in Arizona for flat-tailed ",
"horned lizards <i>Phrynosoma mcallii</i> (Royle & Young Ecology 89, 2281--2289)")
else if (input$secrdatabox == 'housemouse')
x <- HTML("<i>Mus musculus</i> live-trapping data of H. N. Coulombe published ",
"as a CAPTURE example by Otis et al. (1978) Wildlife Monographs 62 ")
else if (input$secrdatabox %in% c('ovenCHp'))
x <- HTML("Multi-year mist-netting study of ovenbirds ",
"<i>Seiurus aurocapilla</i> at a site in Maryland, USA ",
"(Dawson and Efford 2009) (nets as binary proximity detectors)")
else if (input$secrdatabox == 'OVpossumCH')
x <- HTML("Brushtail possum <i>Trichosurus vulpecula</i> live trapping in the ",
"Orongorongo Valley, Wellington, New Zealand 1996--1997 ",
"(Efford and Cowan In: The Biology of Australian Possums and Gliders ",
"Goldingay and Jackson eds. Pp. 471--483).")
else if (input$secrdatabox == 'possumCH')
x <- HTML("Brushtail possum <i>Trichosurus vulpecula</i> live trapping at ",
"Waitarere, North Island, New Zealand April 2002 (Efford et al. 2005 ",
"Wildlife Society Bulletin 33, 731--738)")
else if (input$secrdatabox %in% c('lineoCH'))
x <- HTML(" Multi-session skink (",
"<i>O. lineoocellatum</i>) pitfall trapping data from Lake Station, ",
"Upper Buller Valley, South Island, New Zealand (M. G. Efford, ",
"B. W. Thomas and N. J. Spencer unpublished). ")
else if (input$secrdatabox %in% c('infraCH'))
x <- HTML(" Multi-session skink (<i>Oligosoma infrapunctatum</i>) ",
"pitfall trapping data from Lake Station, ",
"Upper Buller Valley, South Island, New Zealand (M. G. Efford, ",
"B. W. Thomas and N. J. Spencer unpublished). ")
else if (input$secrdatabox == 'stoatCH')
x <- HTML("Stoat <i>Mustela erminea</i> hair tube DNA data from Matakitaki ",
"Valley, South Island, New Zealand (Efford, Borchers and Byrom 2009).")
helpText(x)
})
output$moveswarningui <- renderUI({
if (ms(capthist())) {
if (input$movesallbox)
ch <- join(capthist())
else
ch <- capthist()[[input$sess]]
}
else {
ch <- capthist()
}
captperoccasion <- table(apply(ch != 0, c(1,2), sum))
ncap <- as.numeric(names(captperoccasion))
withinoccasionrecap <- 0
if (any (ncap>1)) {
withinoccasionrecap <- sum(captperoccasion[ncap>1] * (ncap[ncap>1]-1))
}
x <- NULL
if (withinoccasionrecap>0) {
x <- HTML("Warning: detector allows within-occasion re-detections ( n = ", withinoccasionrecap,
") whose order in time is unknown; corresponding movements are unreliable.")
}
helpText(x)
})
#-----------------------------------------------------------------------------
output$sessionnumberui <- renderUI({
x <- NULL
if (ms(capthist())) {
if (input$movesallbox) {
x <- HTML("Sessions combined")
}
else {
x <- HTML("Session ", input$sess, " selected on Array tab")
}
}
helpText(x)
})
#-----------------------------------------------------------------------------
output$timelimitui <- renderUI({
req(timerv)
x <- paste0("Time limit ", timerv$timelimit, " minutes")
helpText(x)
})
#-----------------------------------------------------------------------------
output$ncoresui <- renderUI({
x <- paste0(availablecores, " cores available")
helpText(x)
})
#-----------------------------------------------------------------------------
output$secrdesignurl <- renderUI ({
if (is.null(fitrv$value) & !is.null(capthist())) {
LL <- try(fitmodel(LLonly = TRUE) , silent = TRUE)
LL <- try(fitmodel(LLonly = TRUE) , silent = TRUE)
LL <- try(fitmodel(LLonly = TRUE) , silent = TRUE)
if (is.null(LL) || inherits(LL, 'try-error')) {
NULL # tag$a(" ")
}
else {
timerv$expected <- timefn(LL)
tags$a(paste0('Fit time ~', format(round(timerv$expected,2), nsmall=2), ' min'))
}
}
else {
# only show after model fitted
req(fitrv$value)
parm <- c(
paste0("detectfnbox=", input$detectfnbox),
paste0("distributionbtn=", input$distributionbtn),
paste0("detector=", detector(traprv$data)[1])
)
if (!is.null(input$trapfilename)) {
parm <- c(parm,
paste0("trapotherargs=", input$trapotherargs))
}
if (!is.null(captrv$data)) {
parm <- c(parm,
paste0("noccasions=", as.character(noccasions())))
}
if (!is.null(fitrv$value)) {
parm <- c(parm,
paste0("D=", as.character(signif(density(), input$dec))),
paste0(detectrv$value, "=", as.character(signif(detect0(), input$dec))),
paste0("sigma=", as.character(signif(sigma(), input$dec))))
}
parm <- paste(parm, collapse = "&")
# open secrdesignapp in a new tab, with parameters from secrapp
# designurl is set at top of this file
if (input$detectfnbox %in% c('HHN','HEX') &&
detector(traprv$data)[1] %in% c('multi','proximity','count')) {
tags$a(href = paste0(designurl, "?", parm), "Switch to secrdesign", target="_blank")
}
}
})
#-----------------------------------------------------------------------------
output$persqkm <- renderUI({
## display density in animals/km^2
Dkm <- density() * 100
Dkmtext <- paste0(Dkm, ' animals / km<sup>2</sup>')
helpText(HTML(Dkmtext))
})
#-----------------------------------------------------------------------------
output$detectorhelp <- renderUI({
helptext <- ""
if (input$detector == 'proximity')
helptext <- "binary proximity detector; max. one detection per animal per detector per occasion"
else if (input$detector == 'multi')
helptext <- "multi-catch trap; max. one detection per animal per occasion"
else if (input$detector == 'count')
helptext <- "count proximity detector; integer # detections per animal per occasion"
else if (input$detector == 'single')
helptext <- "single-catch trap; max. one detection per animal & one per trap on any occasion"
else if (input$detector == 'polygon')
helptext <- "searched polygons"
else if (input$detector == 'polygonX')
helptext <- "searched polygons; max. one detection per animal on any occasion"
else if (input$detector == 'transect')
helptext <- "searched transect"
else if (input$detector == 'transectX')
helptext <- "searched transect; max. one detection per animal on any occasion"
helpText(HTML(helptext))
})
#-----------------------------------------------------------------------------
output$captfilehelp <- renderUI({
helptext <- ""
if (input$fmt == "trapID")
helptext <- "Session, ID, Occasion, TrapID"
else
helptext <- "Session, ID, Occasion, X, Y"
helpText(HTML(helptext))
})
#-----------------------------------------------------------------------------
output$shapefile <- renderUI({
helptext <- ""
if (!is.null(input$regionfilename)) {
pos <- grep(".shp", tolower(input$regionfilename[,1]))
if (length(pos)>0)
helptext <- paste0(input$regionfilename[pos,1])
pos <- grep(".rda", tolower(input$regionfilename[,1])) # .rda, .rdata
if (length(pos)>0) {
objlist <- load(input$regionfilename[1,4])
helptext <- paste0(objlist[1])
}
pos <- grep(".rds", tolower(input$regionfilename[,1]))
if (length(pos)>0) {
helptext <- paste0(input$regionfilename[pos,1])
}
}
helpText(HTML(helptext))
})
#-----------------------------------------------------------------------------
output$habitatfile <- renderUI({
helptext <- ""
if (!is.null(polyrv$data)) {
pos <- grep(".shp", tolower(input$maskpolyfilename[,1]))
if (length(pos)>0)
helptext <- paste0(input$maskpolyfilename[pos,1])
pos <- grep(".rda", tolower(input$maskpolyfilename[,1])) # .rda, .rdata
if (length(pos)>0) {
objlist <- load(input$maskpolyfilename[1,4])
helptext <- paste0(objlist[1])
}
pos <- grep(".rds", tolower(input$maskpolyfilename[,1]))
if (length(pos)>0) {
helptext <- paste0(input$maskpolyfilename[pos,1])
}
}
helpText(HTML(helptext))
})
#-----------------------------------------------------------------------------
output$covariatefile <- renderUI({
helptext <- ""
if (!is.null(covariaterv$data)) {
pos <- grep(".shp", tolower(input$maskcovariatefilename[,1]))
if (length(pos)>0)
helptext <- paste0(input$maskcovariatefilename[pos,1])
pos <- grep(".rda", tolower(input$maskcovariatefilename[,1])) # .rda, .rdata
if (length(pos)>0) {
objlist <- load(input$maskcovariatefilename[1,4])
helptext <- paste0(objlist[1])
}
pos <- grep(".rds", tolower(input$maskcovariatefilename[,1]))
if (length(pos)>0) {
helptext <- paste0(input$maskcovariatefilename[pos,1])
}
pos <- grep(".txt", tolower(input$maskcovariatefilename[,1]))
if (length(pos)>0) {
helptext <- paste0(input$maskcovariatefilename[pos,1])
}
}
helpText(HTML(helptext))
})
#-----------------------------------------------------------------------------
output$uigridlines <- renderUI({
if(input$gridlines=="None")
helpText("")
else if (input$gridlines=="100")
helpText(span(style="color:gray", HTML("100-m grid")))
else
helpText(span(style="color:gray", HTML(paste0(round(as.numeric(input$gridlines)/1000,1), "-km grid"))))
})
#-----------------------------------------------------------------------------
output$uipopN <- renderUI({
N <- nrow(pop())
if (is.null(pop()) || !input$Dshowpopn)
helpText("")
else
helpText(HTML(paste0("N = ", N)))
})
#-----------------------------------------------------------------------------
output$xycoord <- renderUI({
xy <- c(input$arrayHover$x, input$arrayHover$y)
tmpgrid <- isolate(traprv$data)
if (ms(tmpgrid)) tmpgrid <- tmpgrid[[input$sess]] ## 2020-08-16
tmpcapt <- capthist()
if (ms(tmpcapt)) {
tmpcapt <- tmpcapt[[input$sess]]
tmpgrid <- traps(tmpcapt)
}
if (is.null(xy))
helpText("")
else {
if (detector(tmpgrid)[1] %in% polygondetectors) {
if (!is.null(tmpcapt)) {
nearest <- nearesttrap(xy, xy(tmpcapt))
## updateNumericInput(session, "animal", value = animalID(tmpcapt, names=FALSE)[nearest])
id <- paste0(animalID(tmpcapt)[nearest], ":")
}
else {
nearest <- nearesttrap(xy, tmpgrid)
id <- polyID(tmpgrid)[nearest]
}
}
else {
nearest <- nearesttrap(xy, tmpgrid)
id <- paste0(rownames(tmpgrid)[nearest], ":")
xy <- tmpgrid[nearest,]
}
# 2020-02-22 this is transient on capthist plot
# as plot is redrawn when new animal selected
helpText(HTML(paste(id, paste(round(xy), collapse = ", "))))
}
})
##############################################################################