From 9fc012d6aba4c19fc87bdb2c33609527f4fd88af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Todor=20Kondi=C4=87?= <todor.kondic@uni.lu> Date: Mon, 28 Feb 2022 14:44:44 +0100 Subject: [PATCH] shiny-ui-base, app: Add download button. --- R/shiny-ui-base.R | 25 +++++++++++++++++++++++++ inst/rmd/app.Rmd | 28 +++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/R/shiny-ui-base.R b/R/shiny-ui-base.R index 088781e..993910e 100644 --- a/R/shiny-ui-base.R +++ b/R/shiny-ui-base.R @@ -1414,6 +1414,7 @@ mk_shinyscreen_server <- function(projects,init) { create_plots(rvs$m) }) + observeEvent(input$make_report_b, { shinymsg("Started creating report. Please wait.") req(NROW(rvs$m$out$tab$flt_summ)>0) @@ -1857,6 +1858,30 @@ mk_shinyscreen_server <- function(projects,init) { }) + output$dwn_proj_b <- shiny::downloadHandler( + filename=function() { + format(Sys.time(), "project_%Y%m%d_%H_%M_%S.tar.gz") + }, + content=function(file) { + pdir <- rvs$m$conf$project + shiny::req(!is.null(pdir) && + !is.na(pdir) && + (nchar(pdir) > 0)) + ddir <- tempfile("projectdata",tmpdir=".") + if (dir.exists(ddir)) unlink(ddir,recursive=T) + dir.create(ddir) + srcfig <- file.path(pdir,'figures') + file.copy(from=srcfig,to=ddir,recursive=T,copy.date=T) + csvfns <- list.files(path=pdir,pattern=r"(.*\.csv$)",full.names=T) + ymlfns <- list.files(path=pdir,pattern=r"(.*\.y.ml$)",full.names=T) + pdffns <- list.files(path=pdir,pattern=r"(.*\.pdf$)",full.names=T) + fns <- c(csvfns,ymlfns,pdffns) + for (fn in fns) {file.copy(from=fn,to=ddir,copy.date=T)} + tar(file,files=ddir,compression="gzip") + unlink(ddir,recursive=T) + }) + + diff --git a/inst/rmd/app.Rmd b/inst/rmd/app.Rmd index a3feed5..89798f0 100644 --- a/inst/rmd/app.Rmd +++ b/inst/rmd/app.Rmd @@ -120,10 +120,9 @@ actionButton(inputId = "create_proj_b", <summary>Load an existing project</summary> All the existing projects are shown in the `Avaliable projects` -list. Load the project by pressing `Select project` button. - - +list. Load the project by pressing `Select project` button. </details> + ```{r, echo=F} selectInput('proj_list', label = "Select project", @@ -133,12 +132,35 @@ actionButton(inputId = "load_proj_b", ``` + ##### Save project ```{r, echo=F} actionButton(inputId = "save_proj_b", label= "Save project") ``` +##### Download project + +<details> +<summary>Download results</summary> + +Button `Download project` only makes sense to be used if Shinyscreen is +served over network. If this is the case, clicking this button will +download plots and csvs generated in the project directory. +</details> + +```{r, echo=F} +downloadButtonRmd <- function (outputId, label = "Download", class = NULL, ...) { + tags$a(id = outputId, class = paste("btn btn-default shiny-download-link", + class), href = "", target = "_blank", download = NA, + icon("download"), label, ...) + } + +downloadButtonRmd("dwn_proj_b", + "Download project directory") +``` + + ##### Select input directory <details> <summary>More on input directories</summary> -- GitLab