-
Notifications
You must be signed in to change notification settings - Fork 0
/
app2.R
103 lines (87 loc) · 2.75 KB
/
app2.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
library(shiny)
library(shinythemes)
library(FLCore)
library(FLa4a)
library(plotly)
library(reshape2)
library(ggplotFL); theme_set(theme_bw())
## Only run examples in interactive R sessions
ui <- fluidPage(
# Input files
fileInput("file1", label = "Stock object"),
fileInput("file2", label = "Index object"),
textInput("fmodel", "fmodel :",value = ""),
textInput("qmodel", "qmodel (separate qmodels with &) :",value = "~factor(replace(age,age>3,3))"),
textInput("srmodel", "srmodel :",value = ""),
textOutput("debug"),
plotOutput("assessment"),
actionButton("run","Run Assessment")
)
server <- function(input, output) {
### Create stk object from input data:
stk <- reactive({
if ( is.null(input$file1)) return(NULL)
inFile <- input$file1
file <- inFile$datapath
# load the file into new environment and get it from there
e = new.env()
name <- load(file, envir = e)
return(e[[name]])
})
### Create index object from input data:
idx <- reactive({
if ( is.null(input$file2)) return(NULL)
inFile <- input$file2
file <- inFile$datapath
# load the file into new environment and get it from there
e = new.env()
name <- load(file, envir = e)
return(e[[name]])
})
### Built models for MANUAL
fmod_2 <- reactive({
return(as.formula(input$fmodel))
})
qmod_2 <- reactive({
y <- unlist(strsplit(input$qmodel,"&"))
ls <- list()
for(i in 1:length(y)){ls[[i]] <- y[i]}
ls <- lapply(ls, formula)
return(ls)
})
srmod_2 <- reactive({
return(as.formula(input$srmodel))
})
############ Basic assessment function ##############
# sca reactive function
# output$debug <- renderText({
# paste0("fmodel: ", as.character(fmod_2()), " qmodel: ", as.character(qmod_2()))
# })
# output$assessment <- renderPlot({
# stk.a4a <- stk() + fit()
# plot(stk.a4a)
# })
#
# fit <- reactive({
# return(sca(stk(),idx(), fmodel = fmod_2(), qmodel = qmod_2(), srmodel = srmod_2()))
# })
# observeEvent(input$run,{
# fit <- reactive({
# return(sca(stk(),idx(), fmodel = fmod_2(), qmodel = qmod_2(), srmodel = srmod_2()))
# })
#
# output$assessment <- renderPlot({
# stk.a4a <- stk() + fit()
# plot(FLStocks(fitted = stk.a4a, catch = stk()))
# })
# })
#
fit <- eventReactive(input$run,{
return(sca(stk(),idx(), fmodel = fmod_2(), qmodel = qmod_2(), srmodel = srmod_2()))
})
output$assessment <- renderPlot({
stk.a4a <- stk() + fit()
plot(FLStocks(fitted = stk.a4a, catch = stk()))
})
}
shinyApp(ui, server)