-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
106 lines (101 loc) · 2.83 KB
/
server.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
library(shiny)
source("selex_fxns.R")
server <- function(input, output, session) {
# Input for logistic parameters;
# make sure sliders and numeric inputs show the same thing
observe({
updateNumericInput(session, "par2N", value = input$par2)
})
observe({
updateSliderInput(session, "par2", value = input$par2N)
})
observe({
updateNumericInput(session, "par1N", value = input$par1)
})
observe({
updateSliderInput(session, "par1", value = input$par1N)
})
# Input for double normal parameters: all parameters on the scale the user enters in SS3
# gray out slider and write in box if using -999 instead;
observeEvent(input$use_999_init, {
if (input$use_999_init == TRUE) {
disable("par.e")
disable("par.eN")
} else {
enable("par.e")
enable("par.eN")
}
})
observeEvent(input$use_999_fin, {
if (input$use_999_fin == TRUE) {
disable("par.f")
disable("par.fN")
} else {
enable("par.f")
enable("par.fN")
}
})
# make sure sliders and numeric iputs show the same thing
observe({
updateNumericInput(session, "par.aN", value = input$par.a)
})
observe({
updateSliderInput(session, "par.a", value = input$par.aN)
})
observe({
updateNumericInput(session, "par.bN", value = input$par.b)
})
observe({
updateSliderInput(session, "par.b", value = input$par.bN)
})
observe({
updateNumericInput(session, "par.cN", value = input$par.c)
})
observe({
updateSliderInput(session, "par.c", value = input$par.cN)
})
observe({
updateNumericInput(session, "par.dN", value = input$par.d)
})
observe({
updateSliderInput(session, "par.d", value = input$par.dN)
})
observe({
updateNumericInput(session, "par.eN", value = input$par.e)
})
observe({
updateSliderInput(session, "par.e", value = input$par.eN)
})
observe({
updateNumericInput(session, "par.fN", value = input$par.f)
})
observe({
updateSliderInput(session, "par.f", value = input$par.fN)
})
# get the lengths (or ages) based on the range the user inputs.
# note using 0.1 bins.
len <- reactive({
seq(as.numeric(input$range[1]), as.numeric(input$range[2]), 0.1)
})
# Calculate the selectivity based on user input
selex <- reactive({
switch(input$type,
"Logistic (1)" = logistic1.fn(len(), input$par1, input$par2),
"Double Normal (24 length, 20 age)" = doubleNorm24.fn(
len(), input$par.a, input$par.b,
input$par.c, input$par.d,
input$par.e, input$par.f,
use_e_999 = input$use_999_init,
use_f_999 = input$use_999_fin
)
)
})
# Create the plot title
output$caption <- renderText({
input$type
})
# creat the plot
output$selPlot <- renderPlot({
plot(len(), selex(), type = "l", lwd = 3, xlab = "Length or Age", ylab = "Selectivity", ylim = c(0, 1))
})
}