From ef9f873818642ba963d6c1f9ab0d90fcf67bc010 Mon Sep 17 00:00:00 2001 From: lakikowolfe Date: Fri, 2 Feb 2024 17:19:06 -0800 Subject: [PATCH 1/3] refactor to handle new configuraiton set up --- R/mod_select_dcc.R | 111 ++++++++++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 41 deletions(-) diff --git a/R/mod_select_dcc.R b/R/mod_select_dcc.R index 1d0eac9..7325e2d 100644 --- a/R/mod_select_dcc.R +++ b/R/mod_select_dcc.R @@ -3,30 +3,24 @@ #' @description A shiny module. Outputs a selectInput dropdown of Synapse #' storage project names to the UI. #' -#' @param id module id -#' @param dcc_config DCC configuration file sourced from -#' `Sage-Bionetworks/data_flow_config` +#' @param id Module id +#' @param title Title of box element #' #' @importFrom shiny NS tagList #' @export mod_select_dcc_ui <- function(id, - dcc_config) { + title = "Select a DCC") { ns <- shiny::NS(id) shiny::tagList( + shinyjs::useShinyjs(), + shinydashboard::box( - title = "Select a DCC", + title = title, # DCC dropdown - shiny::selectInput( - inputId = ns("select_dcc"), - label = NULL, - choices = stats::setNames( - dcc_config$synapse_asset_view, - dcc_config$project_name - ) - ), + shiny::uiOutput(ns("dcc_dropdown")), # Button to initiate selection shiny::actionButton( @@ -40,63 +34,98 @@ mod_select_dcc_ui <- function(id, #' Select a DCC Module Server #' #' @param id module ID -#' @param dcc_config DCC configuration file sourced from +#' @param tenants_config_path DCC configuration file sourced from #' `Sage-Bionetworks/data_flow_config` #' @param access_token Synapse PAT #' #' @export mod_select_dcc_server <- function(id, - dcc_config, + tenants_config_path, access_token) { shiny::moduleServer(id, function(input, output, session) { ns <- session$ns # check that inputs are not reactive - if (shiny::is.reactive(dcc_config)) { - stop("dcc_config must not be a reactive") + if (shiny::is.reactive(tenants_config_path)) { + stop("tenants_config_path must not be a reactive") } if (shiny::is.reactive(access_token)) { stop("access_token must not be a reactive") } - # put asset views into named list + # get tenants config + tenants_config <- jsonlite::read_json( + path = tenants_config_path, + simplifyVector = TRUE + ) + + tenants_config <- tenants_config$tenants + + # put asset views into named vector all_asset_views <- stats::setNames( - dcc_config$synapse_asset_view, - dcc_config$project_name + tenants_config$synapse_asset_view, + tenants_config$name ) - # only display asset_views that user has access to + # determine which asset views user has access to has_access <- vapply(all_asset_views, function(x) { synapse_access(id = x, access = "DOWNLOAD", auth = access_token) }, 1) - asset_views <- all_asset_views[has_access == 1] + visible_tenants <- tenants_config[has_access == 1,] - # if there are no asset_views available, stop - if (length(asset_views) == 0) { - stop("You do not have DOWNLOAD access to any supported Asset Views.") - } + observe({ - # update selectInput with available dccs - shiny::updateSelectInput( - session = session, - inputId = "select_dcc", - choices = asset_views - ) + # if there are no asset_views available, stop + if (nrow(visible_tenants) == 0) { - # if there is only one asset_view available, go straight to dash by - # updating the selected tabItem - if (length(asset_views) == 1) { - shinyjs::click("submit_btn") - } + stop("You do not have DOWNLOAD access to any supported Asset Views.") + + } else if (nrow(visible_tenants) == 1) { - # on button click return: - # 1) selected dcc configuration - # 2) the button click + # if only 1 tenant skip drop down selection + shinyjs::click("submit_btn") + + } else { + + # populate dropdown with available asset views + output$dcc_dropdown <- renderUI({ + shiny::selectInput( + inputId = ns("selected_dcc"), + label = NULL, + choices = stats::setNames( + visible_tenants$synapse_asset_view, + visible_tenants$name + ) + ) + }) + } + }) + + # on button click: + # get dcc specific configuration + # return configuration + button click output shiny::eventReactive(input$submit_btn, { + + # get selected tenant info + if (nrow(visible_tenants) == 1) { + tenant <- visible_tenants + } else { + tenant <- visible_tenants[visible_tenants$synapse_asset_view == input$selected_dcc,] + } + + # get tenant dfa config + config <- jsonlite::read_json( + path = file.path( + dirname(tenants_config_path), + tenant$config_location + ), + ) + + # return a list with config and btn click output list( - selected_dcc_config = dcc_config[dcc_config$synapse_asset_view == input$select_dcc,], + selected_dcc_config = config, btn_click = input$submit_btn ) }) From 91e8eedcce80cc987febd90b0a516f5dd41c94cf Mon Sep 17 00:00:00 2001 From: lakikowolfe Date: Fri, 2 Feb 2024 17:19:29 -0800 Subject: [PATCH 2/3] document --- man/mod_select_dcc_server.Rd | 4 ++-- man/mod_select_dcc_ui.Rd | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/man/mod_select_dcc_server.Rd b/man/mod_select_dcc_server.Rd index eb56e85..dd34dd2 100644 --- a/man/mod_select_dcc_server.Rd +++ b/man/mod_select_dcc_server.Rd @@ -4,12 +4,12 @@ \alias{mod_select_dcc_server} \title{Select a DCC Module Server} \usage{ -mod_select_dcc_server(id, dcc_config, access_token) +mod_select_dcc_server(id, tenants_config_path, access_token) } \arguments{ \item{id}{module ID} -\item{dcc_config}{DCC configuration file sourced from +\item{tenants_config_path}{DCC configuration file sourced from \code{Sage-Bionetworks/data_flow_config}} \item{access_token}{Synapse PAT} diff --git a/man/mod_select_dcc_ui.Rd b/man/mod_select_dcc_ui.Rd index b177085..ba2e2e9 100644 --- a/man/mod_select_dcc_ui.Rd +++ b/man/mod_select_dcc_ui.Rd @@ -4,13 +4,12 @@ \alias{mod_select_dcc_ui} \title{Select a DCC UI} \usage{ -mod_select_dcc_ui(id, dcc_config) +mod_select_dcc_ui(id, title = "Select a DCC") } \arguments{ -\item{id}{module id} +\item{id}{Module id} -\item{dcc_config}{DCC configuration file sourced from -\code{Sage-Bionetworks/data_flow_config}} +\item{title}{Title of box element} } \description{ A shiny module. Outputs a selectInput dropdown of Synapse From 8604684b1326151d3228e476310cfa1b3f44344f Mon Sep 17 00:00:00 2001 From: lakikowolfe Date: Mon, 5 Feb 2024 14:55:38 -0800 Subject: [PATCH 3/3] increment version to 24.2.1 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index e265c3c..d055a18 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: dfamodules Title: Modules for the Data Flow App -Version: 24.1.1 +Version: 24.2.1 Authors@R: person("Loren", "Wolfe", email = "loren.wolfe@sagebase.org", role = c("aut", "cre")) Description: Modules and functions for the Data Flow App.