diff --git a/R/api.R b/R/api.R index 38051139933394742cf65144874509fcef3f6e90..65d7014bc5113592e0b79d62e297780372b96ee5 100644 --- a/R/api.R +++ b/R/api.R @@ -700,22 +700,22 @@ create_plots <- function(m) { #' `rmarkdown::run` `shiny_args` argument. #' @param render_args `list`, optional list of arguments conveyed to #' `rmarkdown::run` `render_args` argument. -#' @param indir `character(1)`, a location on the server side +#' @param top_data_dir `character(1)`, a location on the server side #' containing data directories. -#' @param userdir `character(1)`, a location on the server side containing project directories. +#' @param projects `character(1)`, a location on the server side containing project directories. #' @return Nada. #' @author Todor Kondić -app <- function(shiny_args=list(launch.browser=F),render_args=NULL,indir=getwd(),userdir=getwd()) { +app <- function(shiny_args=list(launch.browser=F),render_args=NULL,top_data_dir=getwd(),projects=getwd()) { dir_before <- getwd() init <- list() init$dir_before <- dir_before - init$indir <- norm_path(indir) - init$userdir <- norm_path(userdir) - if (!dir.exists(init$indir)) stop("Data directory (indir), currently `", - init$indir, + init$top_data_dir <- norm_path(top_data_dir) + init$projects <- norm_path(projects) + if (!dir.exists(init$top_data_dir)) stop("Data directory (top_data_dir), currently `", + init$top_data_dir, "` does not exist. Abort.") - if (!dir.exists(init$userdir)) stop("User root directory (userdir), currently `", - init$userdir,"` does not exist.. Abort.") + if (!dir.exists(init$projects)) stop("User root directory (projects), currently `", + init$projects,"` does not exist.. Abort.") on.exit(expr=setwd(dir_before)) dir_start <- tempfile("shinyscreen") @@ -731,27 +731,27 @@ app <- function(shiny_args=list(launch.browser=F),render_args=NULL,indir=getwd() #' @export #' @title serve -#' @param indir `character(1)`, a location on the server side +#' @param top_data_dir `character(1)`, a location on the server side #' containing data directories. -#' @param topuserdir `character(1)`, a location on the server side +#' @param usersdir `character(1)`, a location on the server side #' containing individual user directories. -#' @param user `character(1)`, subdir of topuserdir. +#' @param user `character(1)`, subdir of usersdir. #' @param host `character(1)`, optional, address where the page is #' served. #' @param port `integer(1)`, optional, port at which the page is #' served. #' @return Nada. #' @author Todor Kondić -serve <- function(indir,topuserdir,user,host='0.0.0.0',port=7777) { +serve <- function(top_data_dir,usersdir,user,host='0.0.0.0',port=7777) { shiny_args <- c(list(launch.browser=F),list(host=host,port=port)) - userdir <- file.path(topuserdir,user) - if (!dir.exists(userdir)) { - dir.create(userdir) - message('Created userdir: ',userdir) + projects <- file.path(usersdir,user) + if (!dir.exists(projects)) { + dir.create(projects) + message('Created projects: ',projects) } else { - message('Using existing userdir: ', userdir) + message('Using existing projects: ', projects) } - app(shiny_args=shiny_args,indir=indir,userdir=userdir) + app(shiny_args=shiny_args,top_data_dir=top_data_dir,projects=projects) } diff --git a/R/shiny-ui-base.R b/R/shiny-ui-base.R index f9d3d542d4e2b522c540672966babc9f8433b21f..c730e229425c9aa0adf4b6e13b94e9a42084e252 100644 --- a/R/shiny-ui-base.R +++ b/R/shiny-ui-base.R @@ -929,51 +929,51 @@ mk_shinyscreen_server <- function(projects,init) { ## OBSERVERS: PROJECT MANAGEMENT observe({ - indir <- rvs$gui$paths$project - req(isTruthy(indir) && dir.exists(indir)) + top_data_dir <- rvs$gui$paths$project + req(isTruthy(top_data_dir) && dir.exists(top_data_dir)) updateSelectInput(session = session, inputId = "comp_list", - choices = list.files(path=indir, + choices = list.files(path=top_data_dir, pattern = CMPD_LIST_PATT)) updateSelectInput(session = session, inputId = "set_list", - choices = list.files(path=indir, + choices = list.files(path=top_data_dir, pattern = SET_LIST_PATT)) updateSelectInput(session = session, inputId = "dfile_list", - choices = list.files(path=indir, + choices = list.files(path=top_data_dir, pattern = DFILES_LIST_PATT)) updateSelectInput(session = session, - inputId = "indir_list", - selected = basename(indir), - choices = list.dirs(path = init$indir, + inputId = "top_data_dir_list", + selected = basename(top_data_dir), + choices = list.dirs(path = init$top_data_dir, full.names = F, recursive = F)) }) observe({ - indir <- rvs$gui$paths$data - req(isTruthy(indir) && dir.exists(indir)) + top_data_dir <- rvs$gui$paths$data + req(isTruthy(top_data_dir) && dir.exists(top_data_dir)) updateSelectInput(session = session, inputId = "dfile_list", - choices = list.files(path=indir, + choices = list.files(path=top_data_dir, pattern = DFILES_LIST_PATT)) }) ## Update projects and data directories every second. observeEvent(rtimer1000(),{ projects <- rv_projects() - curr_projects <- list.dirs(path=init$userdir, full.names = F, recursive = F) + curr_projects <- list.dirs(path=init$projects, full.names = F, recursive = F) if (length(union(curr_projects,projects)) != length(intersect(curr_projects,projects))) { updateSelectInput(session=session, inputId="proj_list", choices=curr_projects) updateSelectInput(session=session, - inputId="indir_list", + inputId="top_data_dir_list", choices=curr_projects) rv_projects(curr_projects) } @@ -986,7 +986,7 @@ mk_shinyscreen_server <- function(projects,init) { ## loaded. Everything else works off rvs$m and rvs$gui. wd <- input$proj_list req(!is.null(wd) && !is.na(wd) && nchar(wd)>0) - fullwd <- file.path(init$userdir,wd) + fullwd <- file.path(init$projects,wd) fullwdq <- file.exists(fullwd) if (!fullwdq) { stop("The project path does not exist!?") @@ -999,7 +999,7 @@ mk_shinyscreen_server <- function(projects,init) { pack <- readRDS(file=fn_packed_state) rvs$gui <- unpack_app_state(session=session, input=input, - top_data_dir=init$indir, + top_data_dir=init$top_data_dir, project_path=fullwd, packed_state=pack) ## Load computational state. @@ -1052,10 +1052,10 @@ mk_shinyscreen_server <- function(projects,init) { shinymsg("Saving state completed.") }) - observeEvent(input$sel_indir_b,{ - indir <- input$indir_list - req(isTruthy(indir)) - rvs$gui$paths$data <- file.path(init$indir, indir) + observeEvent(input$sel_data_dir_b,{ + data_dir <- input$top_data_dir_list + req(isTruthy(data_dir)) + rvs$gui$paths$data <- file.path(init$top_data_dir, data_dir) message("Selected data dir:",rvs$gui$paths$data) diff --git a/R/state.R b/R/state.R index 5bfb605bc607be4234d7e33de492c65103ce68be..319cb100feae1a6a5ee459fe66ee28dfd89466a4 100644 --- a/R/state.R +++ b/R/state.R @@ -40,7 +40,7 @@ runtime_from_conf <- function(run,conf) { run } -reinit_run_data <- function(userdir,top_data_dir,project,run=NULL) { +reinit_run_data <- function(projects,top_data_dir,project,run=NULL) { if (!is.null(run)) { olddata <- run$paths$data oldproject <- basename(run$paths$project) @@ -51,7 +51,7 @@ reinit_run_data <- function(userdir,top_data_dir,project,run=NULL) { if (isTruthy(olddata)) run$paths$data <- file.path(top_user_dir,basename(olddata)) } run$project <- project - run$paths$project <- file.path(userdir,project) + run$paths$project <- file.path(projects,project) run } diff --git a/inst/rmd/app.Rmd b/inst/rmd/app.Rmd index b263be171cd5d80161701629255fa02998f6db3e..1f099797835cf952608f8ba6c09fb5644816c3d5 100644 --- a/inst/rmd/app.Rmd +++ b/inst/rmd/app.Rmd @@ -58,8 +58,8 @@ rv_rtrange <- reactiveValues(min=def_state$conf$rt_min, rv_mzrange <- reactiveValues(min=NA, max=NA) -projects <- list.dirs(path=init$userdir, full.names = F, recursive = F) -inputdirs <- list.dirs(path=init$indir, full.names = F, recursive = F) +projects <- list.dirs(path=init$projects, full.names = F, recursive = F) +inputdirs <- list.dirs(path=init$top_data_dir, full.names = F, recursive = F) ``` <style type="text/css"> @@ -78,7 +78,7 @@ inputdirs <- list.dirs(path=init$indir, full.names = F, recursive = F) <summary>Projects, input directories and compound lists</summary> When you start the program with `app` function, you define two -superdirecotories: `userdir` and `indir`. Directory `userdir` contains +superdirectories: `projects` and `top_data_dir`. Directory `projects` contains all the existing projects and any new projects defined during the current session will be saved here. Data inside a project directory consists of intermediate files, saved states and workflow outputs. @@ -93,7 +93,7 @@ settings and selected inputs. Each `Shinyscreen` project needs input data: mass spectrometry files (in mzML format), compound and set lists. These should all be present before starting `Shinyscreen` in one of the directories under -`userdir`. +`projects`. @@ -157,7 +157,7 @@ downloadButtonRmd("dwn_proj_b", <details> <summary>More on data directories</summary> -Data directory is a subdirectory of the `indir` directory which is +Data directory is a subdirectory of the `top_data_dir` directory which is one of the arguments to `app` function used to start Shinyscreen GUI. It contains the `mzML` data files. @@ -167,10 +167,10 @@ Select one of the data directories from the list by clicking the </details> ```{r, echo=F} -selectInput('indir_list', +selectInput('top_data_dir_list', label = "Input directories", choices = inputdirs) -actionButton(inputId = "sel_indir_b", +actionButton(inputId = "sel_data_dir_b", label= "Select") textOutput("curr_data_dir") ```