diff --git a/dev/app.R b/dev/app.R index b3ed2c9..fbebd28 100644 --- a/dev/app.R +++ b/dev/app.R @@ -636,7 +636,7 @@ server <- function(input, output, session) { "Narrower dilution ranges decrease the CIs of rel. potency, and increase the CIs of upper and lower asymptote ratios, ands Hill's slope ratios", ), - tabPanel("Histograms", + tabPanel("Plots", h4("Histograms of parameters"), plotOutput("linerangeCIs"), plotOutput("ratioSlope"), @@ -658,10 +658,10 @@ server <- function(input, output, session) { tabPanel( "Report", h4("Settings for report"), - useShinyjs(), - actionButton("btn2", "Download PDF report", icon = icon("download")), - downloadButton("downloadWizardReport", label = "Download report", class = "butt"), - tags$style(type = "text/css", "#downloadWizardReport {background-color: #4FCBD9; color: black;font-family: Courier New}"), + #useShinyjs(), + #actionButton("btn2", "Download PDF report", icon = icon("download")), + downloadButton("downloadWizardData", label = "Download model and plots", class = "butt"), + tags$style(type = "text/css", "#downloadWizardData {background-color: #4FCBD9; color: black;font-family: Courier New}"), # textInput("Author", "Author", value = ""), # textInput("RepIdentifier", "Report name", value = ""), # textInput("NoP", "Product name", value = ""), @@ -2235,15 +2235,17 @@ server <- function(input, output, session) { ratioDF <- data.frame(WS_name = URMcoefsDF[,1], slopeRatio = slopeRatio, LasRatio = LasRatio, UasRatio = UasRatio) RMcoefsDF <- t(matrix(unlist(RMcoefsL),nrow=6)) - + colnames(RMcoefsDF) <- c("WS name", "lower asymptote","Hill's slope","upper asymptote","log(EC50 ref)","logEC50 difference") Dat$URMcoefsDF <- URMcoefsDF + Dat$ModU <- URMcoefsDF Dat$RestrM <- RMcoefsDF + Dat$ModR <- RMcoefsDF CalcPotDF <- t(matrix(unlist(potEstL),nrow=3)) colnames(CalcPotDF) <- c("rel_potency","lower_CI","upper_CI") Dat$CalcPot <- CalcPotDF # - #### sigmoid plots ---- + #### Wizard sigmoid plots ---- Slope <- as.numeric(URMcoefsDF[1,3]) if (Slope > 0) { @@ -2484,12 +2486,15 @@ server <- function(input, output, session) { if (!is.null(p2)) { #p2 <- Dat$p2 p_dil <- p2 + - annotate("pointrange", x = dils2, y = rep(min_y, length(dils2)), xmin = min(dils2), xmax = max(dils2),colour = "red" ,linetype = 3) + + geom_vline(xintercept = dils2, col = "red", linetype = 2, alpha=0.5) + + annotate("pointrange", x = dils2, y = rep(min_y, length(dils2)), xmin = min(dils2), xmax = max(dils2), + colour = "red" ,linetype = 3, shape=24) + annotate("text", x = dils2, y = rep(min_y + (max_y - min_y) * 0.05, length(dils2)), label = as.character(round(dils2, 3)),colour = "red") + annotate("text", x = dils2[-1] + (max(dils2) - min(dils2)) * 0.05, y = rep(min_y + (max_y - min_y) * 0.1, length(dils2[-1])), - label = as.character(round(dilfactors[-1], 3)),colour = "red") + label = as.character(round(dilfactors[-1], 3)),colour = "red") + # geom_line( # data = as.data.frame(pl_df), aes(x = dils2, y = SAMPLE50), color = "grey15", linetype = 2, # inherit.aes = F @@ -2498,24 +2503,7 @@ server <- function(input, output, session) { # data = as.data.frame(pl_df), aes(x = dils2, y = SAMPLE200), color = "grey15", linetype = 2, # inherit.aes = F # ) + - # geom_vline(xintercept = c(Xbend50, Xbend200), col = "grey15", linetype = 2) + - # { if (input$scenario == "scenario 6") { - # annotate("pointrange", - # x = optdils2, y = rep(min_y + (max_y - min_y) * 0.2, length(optdils2)), - # xmin = min(optdils2), xmax = max(optdils2), color = "seagreen" - # ) - # } - # } + - # { - # if (input$scenario == "scenario 6") { - # annotate("text", - # x = optdils2, y = rep(min_y + (max_y - min_y) * 0.25, length(optdils2)), - # label = as.character(round(optdils2, 3)), color = "seagreen" - # ) - # } - # } + - - + # annotate("text", # x = optdils[1], y = (max_y + min_y) * 0.5, # label = paste("in green: optimal \n dilutions acc. to Whitepaper\n", input$scenario), color = "seagreen", @@ -2525,6 +2513,7 @@ server <- function(input, output, session) { print(p_dil) }) + Dat$DilPlot <- p_dil } # if (!is.null(p2)) } # if !is.null Dat$Mws @@ -2892,30 +2881,53 @@ server <- function(input, output, session) { #### download Wizard report ---- - output$downloadWizardReport <- downloadHandler( - filename = paste0("Report_Meta", Dat$nameRep, ".pdf"), + output$downloadWizardData <- downloadHandler( + + filename = paste0("CompiledData", Dat$nameRep, ".zip"), content = function(file) { + fs <- c() tpdr <- tempdir() - tempReport <- file.path(tpdr, "Doc_BioassayLinReport.Rmd") - file.copy("Doc_BioassayLinReport.Rmd", tempReport, overwrite = TRUE) + filename = paste0("CompiledData", Dat$nameRep, ".zip") + #tempReport <- file.path(tpdr, "Doc_BioassayLinReport.Rmd") + #file.copy("Doc_BioassayLinReport.Rmd", tempReport, overwrite = TRUE) - tempReportc <- file.path(tpdr, "logov2.png") - file.copy("logov2.png", tempReportc, overwrite = TRUE) + #tempReportc <- file.path(tpdr, "logov2.png") + #file.copy("logov2.png", tempReportc, overwrite = TRUE) - rmarkdown::render(tempReport, - output_file = file, - params = list( - FileName = Dat$FileName, - author = Dat$Author, - NoP = Dat$NoP, - Assay = Dat$Assay, - REP = REP, - REPlin = REPlin, - coeffsLin = Dat$coeffs_UN - ), - envir = new.env(parent = globalenv()) - ) - } + # rmarkdown::render(tempReport, + # output_file = file, + # params = list( + # FileName = Dat$FileName, + # author = Dat$Author, + # NoP = Dat$NoP, + # Assay = Dat$Assay, + # REP = REP, + # REPlin = REPlin, + # coeffsLin = Dat$coeffs_UN + # ), + # envir = new.env(parent = globalenv()) + # ) + #browser() + fileOutModU=paste(paste0(tpdr, sep='/', 'unrModelFits'), sep='','.csv') + fs=c(fs, fileOutModU) + ModU <- Dat$ModU + write.csv(ModU, fileOutModU, row.names = F) + + fileOutModR=paste(paste0(tpdr, sep='/', 'restrModelFits'), sep='','.csv') + fs=c(fs, fileOutModR) + ModR <- Dat$ModR + write.csv(ModR, fileOutModR, row.names = F) + + DilPlot <- Dat$DilPlot + fileOutDilPlot =paste(paste0(tpdr, sep='/', 'SigmoidDilutionsPlot'), sep='','.png') + fs=c(fs, fileOutDilPlot) + png(fileOutDilPlot, width=600, height=400) + print(DilPlot) + dev.off() + #browser() + zip::zipr(zipfile=file, files=fs, include_directories = F) + + }, contentType = "application/zip" ) }