[LONGITUDINAL] input = {ka, Tk0, V, k} EQUATION: D = 100 if t>Tk0 f0=D/(V*Tk0*k)*(1-exp(-k*Tk0))*exp(-k*(t-Tk0)) else f0=D/(V*Tk0*k)*(1-exp(-k*t)) end f1 = f0 f2 = D*ka/(V*(ka-k))*(exp(-k*t) - exp(-ka*t))
ui <- shinyUI(fluidPage( navbarPage(" ", tabPanel("Plot", fluidRow( column(2, sliderInput("ka", label="ka",value=0.5,min=0.1,max=1,step=0.1), numericInput("Tk0", label="Tk0",value=2), selectInput("k", label="k", choices=c(0.05,0.2,0.4),selected=0.2), br() ), column(2, br(), checkboxGroupInput("out1", label="plot", choices=c('f1','f2'), selected=c('f1','f2')),hr(), strong("add"), checkboxInput("legend", label="legend", value=TRUE), fluidRow( column(5,checkboxInput("boxref", label="ref.")), column(4,actionButton("butref", label = "Reset")) ), hr(), br() ), column(8,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("mlxR") library("reshape") library("gridExtra") source("shinymlxTools.R") f <- list(name=c('f1','f2'), time=seq(0,20,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('ka', 'Tk0', 'V', 'k'), value = isolate(c(input$ka, input$Tk0, 2, as.numeric(input$k)))) r <- simulx( model = 'model.txt', parameter = p, output = f) ref <- merge_res(r,f) return(ref) }) res <- reactive({ p <- list(name = c('ka', 'Tk0', 'V', 'k'), value = c(input$ka, input$Tk0, 2, as.numeric(input$k))) r <- simulx( model = 'model.txt', 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") } 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) }