-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStageModellingApp.R
104 lines (71 loc) · 2.77 KB
/
StageModellingApp.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
library(shiny)
library(popbio)
# Define UI for app that draws a histogram ----
ui <- fluidPage(
# App title ----
titlePanel("Stage Modelling"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Slider for the number of bins ----
sliderInput(inputId = "Offspring",
label = "Number of offspring:",
min = 0,
max = 12,
value = 5),
sliderInput(inputId = "egg2hatch",
label = "Egg hatch success:",
min = 0,
max = 1,
value = .2),
sliderInput(inputId = "hatch2fledge",
label = "Hatchling survival:",
min = 0,
max = 1,
value = .3),
sliderInput(inputId = "fledge2adult",
label = "Fledgling survival:",
min = 0,
max = 1,
value = .67),
sliderInput(inputId = "adultsurv",
label = "Adult survival:",
min = 0,
max = 1,
value = .85)
),
mainPanel(
fluidRow(
splitLayout(cellWidths = c("70%", "30%"), plotOutput(outputId = "matPlot"), plotOutput(outputId = "Elas")))
)
)
)
server <- function(input, output) {
output$matPlot <- renderPlot({
x <- 0:12
bird<-matrix(c(0,0,0, input$Offspring,
input$egg2hatch,0,0,0,
0,input$hatch2fledge,0,0,
0,0,input$fledge2adult,input$adultsurv),nrow=4,ncol=4,byrow=T)
#now we will start with an initial population vector:
initial.vec<-c(100,20,10,5) #100 eggs, 20 fledglings, 10 young adults and 5 adults
timestep<-100
N<-matrix(0,nrow=length(bird[1,]),ncol=timestep)
N[,1]<-initial.vec
#now for the for loop. We want to multiply the population vector by the matrix for each year of the simulation
for (i in 2:timestep)
{N[,i]<-bird%*%N[,i-1]}
matplot(t(N),type="l",lty=1,lwd=3,col=1:4,xlab="Time",ylab="Population size")
legend(40, max(N), c("Eggs","Hatchlings","Fledglings","Adults"), lty=1, lwd=3, col=1:4, cex=1.2)
})
output$Elas <- renderPlot({
x <- 0:12
bird<-matrix(c(0,0,0, input$Offspring,
input$egg2hatch,0,0,0,
0,input$hatch2fledge,0,0,
0,0,input$fledge2adult,input$adultsurv),nrow=4,ncol=4,byrow=T)
image2(elasticity(bird),col=rev(heat.colors(10)))
})
}
shinyApp(ui = ui, server = server)