DESCRIPTION: Two compartment TMDD model for multiple doses into central compartment [LONGITUDINAL] input = {kel, kep, kon, kout, koff, ktp, kpt, Vc, R0} PK: ; Dosemg: Dose injected into central compartment (mg/kg) ; MWlig=150000; molecular weight of ligand (Da) ; (Dosemg*1e-3/MWlig)*1e9 ; Dose conversion (nmol/kg) depot(target=L, p=100/15/Vc) ; L is a concentration (nM) EQUATION: odeType = stiff kin = kout*R0 ; Synthesis of receptor (nM/day) ;Initial Conditions R_0 = R0 ;Ordinary Differential Equations ddt_L = -kel*L - kon*L*R + koff*P + ktp*Lt - kpt*L ddt_R = kin - kout*R - kon*L*R + koff*P ddt_P = kon*L*R - koff*P - kep*P ddt_Lt= -ktp*Lt + kpt*L
ui <- shinyUI(fluidPage( navbarPage("TMDD - Model 2", tabPanel("Plot", fluidRow( column(2, tabsetPanel(type='tabs', tabPanel('param1',br(), sliderInput("kel", label="kel",value=0.046,min=0.023,max=0.092,step=0.0046), sliderInput("kep", label="kep",value=0.17,min=0.085,max=0.34,step=0.017), sliderInput("kout", label="kout",value=17.3,min=8.65,max=34.6,step=1.73), sliderInput("koff", label="koff",value=169,min=84.5,max=338,step=16.9), br() ), tabPanel('param2',br(), sliderInput("kon", label="kon",value=30.2,min=15.1,max=60.4,step=3.02), sliderInput("ktp", label="ktp",value=0.725,min=0.3625,max=1.45,step=0.0725), sliderInput("kpt", label="kpt",value=0.902,min=0.451,max=1.804,step=0.0902), sliderInput("R0", label="R0",value=0.00657,min=0.003285,max=0.01314,step=0.000657), sliderInput("Vc", label="Vc",value=0.04,min=0.02,max=0.08,step=0.004), br() ), tabPanel('adm',br(), sliderInput("tfd1", label="tfd",value=12,min=0,max=24,step=3), sliderInput("nd1", label="nd",value=4,min=1,max=10,step=1), sliderInput("ii1", label="ii",value=28,min=7,max=112,step=7), sliderInput("amount1", label="amount",value=10,min=0,max=40,step=0.5), br() ), br() ) ), column(2, br(), checkboxGroupInput("out1", label="plot 1", choices='L', selected='L'), selectInput("x1", label="v.s.",c('time','L','R','P')), hr(), checkboxGroupInput("out2", label="plot 2", choices='R', selected='R'), selectInput("x2", label="v.s.",c('time','L','R','P')), hr(), checkboxGroupInput("out3", label="plot 3", choices='P', selected='P'), selectInput("x3", label="v.s.",c('time','L','R','P')), hr() ), column(8,br(), plotOutput("plot"), br(), br(), br(), br(), br(), fluidRow( column(1), column(1,checkboxInput("boxref", label="ref.")), column(3,actionButton("butref", label = "Reset")), column(7,radioButtons("ilog", "scale", c("linear" = FALSE,"log " = TRUE), inline=TRUE)) ) ) ) ), tabPanel("Model", pre(includeText("model.txt"))), tabPanel("ui.R", pre(includeText("ui.R"))), tabPanel("server.R", pre(includeText("server.R"))) ) ))
library("mlxR") library("reshape") library("gridExtra") source("shinymlxTools.R") out1 <- list(name='L', time=seq(0,360,by=1)) out2 <- list(name='R', time=seq(0,360,by=1)) out3 <- list(name='P', time=seq(0,360,by=1)) f <- list(out1, out2, out3) nf <- length(f) info <- info_res(f) server <- function(input, output) { ref <- reactive({ input$butref p <- list(name = c('kel', 'kep', 'kout', 'koff', 'kon', 'ktp', 'kpt', 'R0', 'Vc'), value = isolate(c(input$kel, input$kep, input$kout, input$koff, input$kon, input$ktp, input$kpt, input$R0, input$Vc))) t1 <- isolate(input$tfd1) t2 <- isolate(input$ii1)*(isolate(input$nd1)-1)+t1 t.dose <- seq(t1,t2,by=isolate(input$ii1)) adm <- list(time=t.dose, amount=isolate(input$amount1)) r <- simulx( model = 'model.txt', treatment = adm, parameter = p, output = f) ref <- merge_res(r,f) return(ref) }) res <- reactive({ p <- list(name = c('kel', 'kep', 'kout', 'koff', 'kon', 'ktp', 'kpt', 'R0', 'Vc'), value = c(input$kel, input$kep, input$kout, input$koff, input$kon, input$ktp, input$kpt, input$R0, input$Vc)) t1 <- input$tfd1 t2 <- input$ii1*(input$nd1-1)+t1 t.dose <- seq(t1,t2,by=input$ii1) adm <- list(time=t.dose, amount=input$amount1) 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, aes(x=',xj,',y=',name.fj[k],'),colour="grey",size=0.75)') eval(parse(text=pj)) } pj <- paste0('pl <- pl + geom_path(data=res, aes(x=',xj,',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) print(pl) 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) }