[LONGITUDINAL] input = {F, ka, V, k} PK: depot(type=1, target=Ad, p=F) depot(type=2, target=Ac) EQUATION: ddt_Ad = -ka*Ad ddt_Ac = ka*Ad - k*Ac Cc = Ac/V
ui <- shinyUI(fluidPage( navbarPage(" ", tabPanel("Plot", fluidRow( column(3,br(), tabsetPanel(type='tabs', tabPanel('param',br(), sliderInput("F", label="F",value=0.7,min=0.35,max=1.4,step=0.07), sliderInput("ka", label="ka",value=1,min=0.5,max=2,step=0.1), sliderInput("V", label="V",value=10,min=5,max=20,step=1), sliderInput("k", label="k",value=0.1,min=0.05,max=0.2,step=0.01), br() ), tabPanel('adm1',br(), selectInput("type1", label="type", choices=c(1,2),selected=1), sliderInput("tfd1", label="tfd",value=6,min=0,max=24,step=2), sliderInput("nd1", label="nd",value=3,min=0,max=10,step=1), sliderInput("ii1", label="ii",value=12,min=3,max=24,step=1), sliderInput("amount1", label="amount",value=40,min=0,max=50,step=5), br() ), tabPanel('adm2',br(), selectInput("type2", label="type", choices=c(1,2),selected=2), sliderInput("tfd2", label="tfd",value=12,min=0,max=24,step=2), sliderInput("nd2", label="nd",value=2,min=0,max=10,step=1), sliderInput("ii2", label="ii",value=30,min=6,max=60,step=6), sliderInput("amount2", label="amount",value=20,min=0,max=50,step=5), sliderInput("rate2", label="rate",value=5,min=1,max=10,step=1), br() ), tabPanel('output',br(), fluidRow( column(5,checkboxInput("boxref", label="reference")), column(4,actionButton("butref", label = "Reset")) ), hr(), radioButtons("ilog", "scale", c("linear" = FALSE,"log" = TRUE), inline=TRUE), br() ), br() ) ), column(9,br(), plotOutput("plot") ) ) ), tabPanel("Mlxtran", pre(includeText("model.txt"))), tabPanel("ui.R", pre(includeText("ui.R"))), tabPanel("server.R", pre(includeText("server.R"))) ) ))
source("../../initMlxR.R") library("reshape") library("gridExtra") source("shinymlxTools.R") f <- list(name='Cc', time=seq(0,100,by=0.1)) f <- list(f) nf <- length(f) info <- info_res(f) server <- function(input, output) { ref <- reactive({ input$butref p <- list(name = c('F', 'ka', 'V', 'k'), value = isolate(c(input$F, input$ka, input$V, input$k))) t1 <- isolate(input$tfd1) t2 <- isolate(input$ii1)*(isolate(input$nd1)-1)+t1 t.dose <- seq(t1,t2,by=isolate(input$ii1)) adm1 <- list(time=t.dose, type=isolate(input$type1),amount=isolate(input$amount1)) t1 <- isolate(input$tfd2) t2 <- isolate(input$ii2)*(isolate(input$nd2)-1)+t1 t.dose <- seq(t1,t2,by=isolate(input$ii2)) adm2 <- list(time=t.dose, type=isolate(input$type2),amount=isolate(input$amount2),rate=isolate(input$rate2)) adm <- list(adm1, adm2) r <- simulx( model = 'model.txt', treatment = adm, parameter = p, output = f) ref <- merge_res(r,f) return(ref) }) res <- reactive({ p <- list(name = c('F', 'ka', 'V', 'k'), value = c(input$F, input$ka, input$V, input$k)) t1 <- input$tfd1 t2 <- input$ii1*(input$nd1-1)+t1 t.dose <- seq(t1,t2,by=input$ii1) adm1 <- list(time=t.dose, type=input$type1,amount=input$amount1) t1 <- input$tfd2 t2 <- input$ii2*(input$nd2-1)+t1 t.dose <- seq(t1,t2,by=input$ii2) adm2 <- list(time=t.dose, type=input$type2,amount=input$amount2,rate=input$rate2) adm <- list(adm1, adm2) r <- simulx( model = 'model.txt', treatment = adm, parameter = p, output = f) res <- merge_res(r,f) return(res) }) output$plot <- renderPlot({ res=res() ref=ref() gr.txt <- "grid.arrange(" for (j in (1:length(f))){ xj <- "time" fj <- f[[j]] name.fj <- fj$name eval(parse(text=paste0("inputyj=input$out",j))) i.plot=FALSE if (!is.null(inputyj)){ ij <- which(name.fj %in% inputyj) if (length(ij>0)){ eval(parse(text=paste0("inputxj=input$x",j))) if (!is.null(inputxj)) xj <- inputxj } i.plot=TRUE } else if (is.null(inputyj) & length(f)==1){ ij=1 i.plot=TRUE } if (i.plot){ pl <- ggplotmlx() nfj <- length(name.fj) for (k in (1:nfj)){ if (k %in% ij){ if (input$boxref==TRUE){ pj <- paste0('pl <- pl + geom_path(data=ref[[j]], aes(x=time,y=',name.fj[k],'),colour="grey",size=0.75)') eval(parse(text=pj)) } pj <- paste0('pl <- pl + geom_path(data=res[[j]], aes(x=time,y=',name.fj[k],',colour="',info[[j]]$colour[k],'"),size=0.75)') eval(parse(text=pj)) } } pl <- pl + scale_colour_manual(values=info[[j]]$values, labels=info[[j]]$labels) if (length(ij)>1){ if (!is.null(input$legend) && input$legend==FALSE) pl <- pl + theme(legend.position="none") else pl <- pl + guides(colour=guide_legend(title=NULL)) + theme(legend.position=c(.9, .8)) pl <- pl + ylab("") }else{ pl <- pl + theme(legend.position="none") } if (input$ilog==TRUE) pl=pl + scale_y_log10() eval(parse(text=paste0("pl",j," <- pl"))) gr.txt <- paste0(gr.txt,"pl",j,",") } } gr.txt <- paste0(gr.txt,"ncol=1)") eval(parse(text=gr.txt)) }, height = 500) }