-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
69 lines (49 loc) · 1.79 KB
/
server.R
File metadata and controls
69 lines (49 loc) · 1.79 KB
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
library(shiny)
library(ggplot2)
library(reshape)
# Load model into the local environment
source("model.R", local = TRUE)
# Define server logic required to generate the plot
shinyServer(function(input, output) {
# Capture input variables in a reactive expression
runArgs <- reactive({
# Bind initial state and parameter inputs
return(list(
state = vapply( names(state)
, function(name) { as.numeric(input[[name]]) }
, FUN.VALUE = numeric(1)
)
, parameters = vapply( names(parameters)
, function(name) { as.numeric(input[[name]]) }
, FUN.VALUE = numeric(1)
)
))
})
# Run the model in a reactive expression
runModel <- reactive({
args <- runArgs()
# Simulation time depth
depth <- (time["end"] - time["start"]) / time["step"]
# Run the simulation; convert result to a data.frame
result <- data.frame(solver(
y = args$state
, times = seq(time["start"], input$time.end, by = abs(input$time.end - time["start"]) / depth)
, func = model
, parms = args$parameters
))
return(result)
})
# Simulation plot
output$voltagePlot <- renderPlot({
p <- ggplot(melt(runModel()[,c("time","v")], id = "time")) +
geom_line( aes(time, value, colour = variable) ) +
ylab("mV")
print(p)
})
output$conductancePlot <- renderPlot({
p <- ggplot(melt(runModel()[,c("time","m","h","n")], id = "time")) +
geom_line( aes(time, value, colour = variable) ) +
ylab("[variable]")
print(p)
})
})