-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
160 lines (132 loc) · 5.86 KB
/
app.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
## user-visible changes 2.0 November 2024
## requires secr >= 5.1
## blackbearCH
## suggest width actionlink on Main
## OVforestL left bank only
## replace rgdal with sf:
## st_read; st_as_sfc
## sf_project in secrapp-tutorial
## clear summaries actionLink on Summary
## other changes 2.0
## update for secr 5.1: fxiContour, esaPlot
## limited resultsPrint box height to 350px (scroll for estimates)
## code split following:
## https://stackoverflow.com/questions/43002914/how-to-split-shiny-app-code-over-multiple-files-in-rstudio#43003577
## fix mask fail with polygon + multisession
## fix bugs in select summary fields (tmp$dAIC etc.)
## expected time calculated once in output$secrdesignurl <- renderUI ()
## changes after 2.0
## re-vamped notifications:
# version duration = seconds; startup only
# lastaction duration = seconds
# warning duration = warningseconds
# invalidinput duration = invalidseconds
# error duration = errorseconds
## option to specify mask spacing instead of nx
## new Re-fit button
## re-styled habitat mask summary on main tab
library(secr)
library(shinyjs)
# requires package sf (polygon operations)
# requires package stringr (for some string operations)
# requires package readxl (for reading Excel files)
# requires package parallel for max cores in simulate options (distributed with base R)
# requires package tools for file path when reading shapefiles (distributed with base R)
source('globalvars.R', local = TRUE)
source('tab-intro.R', local = TRUE)
source('tab-main.R', local = TRUE)
source('tab-habitatmask.R', local = TRUE)
source('tab-summary.R', local = TRUE)
source('tab-options.R', local = TRUE)
source('tab-help.R', local = TRUE)
source('tab-about.R', local = TRUE)
if (compareVersion(as.character(secrversion), '5.1.0') < 0)
stop("secrapp 2.1 requires secr version 5.1.0 or later",
call. = FALSE)
if (!requireNamespace('stringr')) stop("please install package 'stringr'")
if (!requireNamespace('sf')) stop("please install package 'sf'")
if (!requireNamespace('readxl')) stop("please install package 'readxl'")
# interrupt is hard -
# see http://htmlpreview.github.io/?https://github.com/fellstat/ipc/blob/master/inst/doc/shinymp.html
############################################################################################
# Define UI
ui <- function(request) {
fluidPage(
title = "secr app 2.1",
includeCSS("secrstyle.css"),
useShinyjs(),
withMathJax(),
br(),
navlistPanel(id = "navlist", widths = c(2,10), well = TRUE, "secr app 2.1",
tabintro,
tabmain,
tabhabitat,
tabsummary,
taboptions,
tabhelp,
tababout
)
)
}
############################################################################################
# Define server logic
server <- function(input, output, session) {
## for cycling through animals at one detector 2019-03-08
lasttrap <- 0
clickno <- 0
# for remembering other function
oldfn <- ""
# source here as these use input or assign to output
source('miscfn.R', local = TRUE)
source('codestringfn.R', local = TRUE)
source('renderUI.R', local = TRUE)
source('renderPlot.R', local = TRUE)
source('renderPrint.R', local = TRUE)
source('renderTable.R', local = TRUE)
source('reactiveValues.R', local = TRUE)
source('reactive.R', local = TRUE)
source('observeEvent.R', local = TRUE)
source('observe.R', local = TRUE)
source('downloadHandler.R', local = TRUE)
source('fitmodel.R', local = TRUE)
source('bookmark.R', local = TRUE)
disable("fitbtn")
disable("refitbtn")
disable("captfilename")
disable("captxlsname")
disable("dummybookmarkbutton")
disable ("habspacing")
output$selectingfields <- renderText('false')
output$selectinganalyses <- renderText('false')
output$summaries <- renderText('false')
output$multisession <- renderText('false')
output$nontrap <- renderText('false')
outputOptions(output, "selectingfields", suspendWhenHidden = FALSE)
outputOptions(output, "selectinganalyses", suspendWhenHidden = FALSE)
outputOptions(output, "summaries", suspendWhenHidden = FALSE)
outputOptions(output, "multisession", suspendWhenHidden = FALSE)
outputOptions(output, "nontrap", suspendWhenHidden = FALSE)
outputOptions(output, "maskready", suspendWhenHidden = FALSE)
outputOptions(output, "maskcovariatesready", suspendWhenHidden = FALSE)
outputOptions(output, "maskcovariatefileready", suspendWhenHidden = FALSE)
outputOptions(output, "maskpolygonsready", suspendWhenHidden = FALSE)
outputOptions(output, "modelFitted", suspendWhenHidden = FALSE)
outputOptions(output, "capthistLoaded", suspendWhenHidden = FALSE)
outputOptions(output, "filterCapt", suspendWhenHidden = FALSE)
outputOptions(output, "filterMask", suspendWhenHidden = FALSE)
outputOptions(output, "usage", suspendWhenHidden = FALSE)
showNotification(paste("secr", secrversion, secryear),
id = "version", type = "message", duration = seconds)
##############################################################################
# tidy end of session - app closes in R
# apparently incompatible with bookmarking 2019-01-17
session$onSessionEnded(function() {
stopApp()
})
##############################################################################
}
## end of server logic
##################################################################################
# Run the application
shinyApp(ui = ui, server = server, enableBookmarking = "server")
##################################################################################