adm1 <- list(time=c(6, 36), amount=40, type=1)
adm2 <- list(time=c(12,42), amount=c(20,30), rate=c(5, 10), type=2)
trt <- list(adm1, adm2)
p <- list(name=c("F","ka","V","k"), value=c(0.7,1,10,0.1))
Cc <- list(name="Cc",time=seq(0, 60, by=0.1))
res <- simulx(model="pk2a_model.txt",parameter=p,output=Cc,treatment=trt)
print(ggplot(data=res$Cc, aes(x=time, y=Cc)) + geom_line())
shinyUI(fluidPage(
titlePanel("Repeated oral and iv administrations",windowTitle="oral and iv administrations"),
tabsetPanel(
tabPanel("oral administration",
fluidRow(
column(3, offset=1,
sliderInput("tfd1", "Time of first dose:", value=0, min=0, max = 20, step=1),
sliderInput("ii1", "Interdose interval:", value = 6, min = 0.5, max = 15, step=0.5)
),
column(3, offset=1,
sliderInput("nd1", "Number of doses:", value=0, min=0, max = 20, step=1),
sliderInput("amt1", "Amount:", value = 5, min = 0, max = 20, step=1)
)
)
),
tabPanel("iv administration",
fluidRow(
column(3, offset=1,
sliderInput("tfd2", "Time of first dose:", value=0, min=0, max = 20, step=1),
sliderInput("ii2", "Interdose interval:", value = 9, min = 0.5, max = 15, step=0.5)
),
column(3, offset=1,
sliderInput("nd2", "Number of doses:", value=0, min=0, max = 10, step=1),
sliderInput("amt2", "Amount:", value = 5, min = 0, max = 20, step=1)
),
column(3, offset=1,
sliderInput("tinf2", "Infusion time:", value = 1, min = 0, max = 5, step=0.2)
)
)
),
tabPanel("PK parameters",
fluidRow(
column(3, offset=1,
sliderInput("F", "bioavailability F:", value = 0.7, min = 0, max = 1, step=0.05) ,
sliderInput("ka", "absorption rate constant ka:", value = 0.8, min = 0, max = 4, step=0.1)
),
column(3, offset=1,
sliderInput("V", "volume V:", value = 10, min = 1, max = 20, step=1),
sliderInput("k", "elimination rate constant k:", value = 0.2, min = 0, max = 4, step=0.05)
)
)
),
tabPanel("Output",
fluidRow(
column(3, offset=1,
sliderInput("range", "time range", min = -10, max = 200, value = c(-5,100), step=5),
sliderInput("ngp", "grid size", min = 10, max = 1000, value = 200, step=10)
)
)
)
),
hr(),
tabsetPanel(
tabPanel("Plot",
fluidRow(
column(10, plotOutput("plot")),
column(2,
sliderInput("lsize", "line size", min = 0, max = 3, value = 0.75, step=0.25)
)
)
),
tabPanel("Table", tableOutput("table")),
tabPanel("Mlxtran", pre(includeText("pk2_model.txt"))),
tabPanel("Simulx", pre(includeText("pk2_simulx.R"))),
tabPanel("ui.R", pre(includeText("ui.R"))),
tabPanel("server.R", pre(includeText("server.R")))
)
))
my.dir=getwd()
source("../initMlxR.R")
setwd(my.dir)
shinyServer(function(input, output) {
r <- reactive({
param.value=c(input$F,input$ka,input$V,input$k)
t.value=seq(input$range[1],input$range[2],length.out=input$ngp)
t11=input$tfd1
t12=input$ii1*(input$nd1-1)+t11
if (t12>=t11){
t1.dose=seq(t11,t12,by=input$ii1)
adm1 <- list(time=t1.dose, amount=input$amt1, type=1)
}else{
adm1 <- list(time=t11, amount=0, type=1)
}
t21=input$tfd2
t22=input$ii2*(input$nd2-1)+t21
if (t22>=t21){
t2.dose=seq(t21,t22,by=input$ii2)
adm2 <- list(time=t2.dose, amount=input$amt2, rate=input$amt2/input$tinf2, type=2)
}else{
adm2 <- list(time=t21, amount=0, type=2)
}
Cc <- list(name='Cc',time=t.value)
p <- list(name=c('F','ka','V','k'), value=param.value)
res <- simulx( model = 'pk2_model.txt',
treatment = list(adm1,adm2),
parameter = p,
output = Cc)
res$Cc
})
output$plot <- renderPlot({
ggplot(data=r(), aes(x=time, y=Cc)) + geom_line(size=input$lsize)
# x=r()$time
# y=r()$Cc
# par(mar=c(5,4,0,2))
# plot(x,y,type='l')
})
output$table <- renderTable({ r() })
})