From faa3805b9dd2ee53ac32005e68067f276080f3a5 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Thu, 5 May 2022 09:37:06 +0930 Subject: [PATCH 01/12] WIP simple prototype app to display one of the analysis gadgets --- inst/shiny/sandbox/server.R | 85 +++++++++++++++++++++++++++++++++++++ inst/shiny/sandbox/ui.R | 27 ++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 inst/shiny/sandbox/server.R create mode 100644 inst/shiny/sandbox/ui.R diff --git a/inst/shiny/sandbox/server.R b/inst/shiny/sandbox/server.R new file mode 100644 index 0000000..c8677d3 --- /dev/null +++ b/inst/shiny/sandbox/server.R @@ -0,0 +1,85 @@ +library(shiny) + +shinyServer(function(input, output, session) { + + debug <- FALSE + bs4dash <- getOption("facile.bs4dash") + options(facile.bs4dash = FALSE) + on.exit(options(facile.bs4dash = bs4dash)) + + x <- reactive({ + switch(req(input$dataset), + "TCGA" = FacileData:::exampleFacileDataSet(), + NULL + ) + }) + + analysisModule <- reactive({ + switch(req(input$analysis), + "fdge" = FacileAnalysis::fdgeAnalysis, + "fpca" = FacileAnalysis::fpcaAnalysis, + "ffsea" = FacileAnalysis::ffseaAnalysis, + NULL + ) + }) + + analysisUI <- reactive({ + switch(req(input$analysis), + "fdge" = FacileAnalysis::fdgeAnalysisUI, + "fpca" = FacileAnalysis::fpcaAnalysisUI, + "ffsea" = FacileAnalysis::ffseaAnalysisUI, + NULL + ) + }) + + observeEvent(input$analysis, { + req(input$analysis != "none") + ui.content <- analysisUI()("analysis", debug = debug) + + ui <- tagList( + FacileShine::filteredReactiveFacileDataStoreUI("ds"), + tags$hr(), + ui.content + ) + + ## NOTE: immediate = TRUE is necessary! + insertUI("#here", "afterEnd", ui, immediate = TRUE) + }) + + ## this logic should be isolated into a function + rfds <- reactive({ + req(input$analysis != "none") + + .x <- x() + if (is(.x, "facile_frame")) { + fds. <- FacileData::fds(.x) + samples. <- .x + sample.filter <- FALSE + restrict_samples <- samples. + } else if (is(.x, "FacileDataStore")) { + sample.filter <- TRUE + fds. <- .x + samples. <- dplyr::collect(FacileData::samples(.x), n = Inf) + } else if (is(.x, "FacileAnalysisResult")) { + # ugh, this isn't going to work -- I'm writing this in to fire up a + # ffseaGadget, whose needs to be a FacileAnalysisResult. + sample.filter <- FALSE + fds. <- FacileData::fds(.x) + samples. <- dplyr::collect(FacileData::samples(.x), n = Inf) + restrict_samples <- samples. + } else { + stop("What in the world?") + } + checkmate::assert_class(fds., "FacileDataStore") + checkmate::assert_class(samples., "facile_frame") + + FacileShine:::ReactiveFacileDataStore(fds., "ds", samples = samples.) + }) + + observe({ + req(input$analysis != "none") + analysis <- callModule(analysisModule(), "analysis", rfds(), debug = debug) + }) + +}) + diff --git a/inst/shiny/sandbox/ui.R b/inst/shiny/sandbox/ui.R new file mode 100644 index 0000000..e0f82aa --- /dev/null +++ b/inst/shiny/sandbox/ui.R @@ -0,0 +1,27 @@ +library(shiny) + +shinyUI(fluidPage( + + # Application title + titlePanel("FacileSandbox"), + + sidebarLayout( + sidebarPanel(width = 3, + + shinyWidgets::pickerInput("dataset", + "Select a dataset", + choices = "TCGA", + selected = "TCGA" + ), + shinyWidgets::pickerInput("analysis", + "Select an analysis:", + choices = c("none", "fdge", "fpca", "ffsea"), + selected = "none" + ) + ), + + mainPanel( + tags$div(id = "here") + ) + ) +)) From 7ba1db70749fec4b71a44e8d4b43ce98cbb099d6 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Thu, 5 May 2022 10:19:49 +0930 Subject: [PATCH 02/12] dynamic add and remove buttons which clean up after themselves --- inst/shiny/sandbox/server.R | 63 ++++++++++++++++++++++++++++++++++--- inst/shiny/sandbox/ui.R | 28 +++++++++-------- 2 files changed, 74 insertions(+), 17 deletions(-) diff --git a/inst/shiny/sandbox/server.R b/inst/shiny/sandbox/server.R index c8677d3..1ad3a3d 100644 --- a/inst/shiny/sandbox/server.R +++ b/inst/shiny/sandbox/server.R @@ -1,7 +1,36 @@ library(shiny) +# https://github.com/Appsilon/dynamic-shiny-modules/blob/3b05aad99f633103788b62a94d8ed198ce4b977b/after.R +remove_shiny_inputs <- function(id, .input) { + invisible( + lapply(grep(id, names(.input), value = TRUE), function(i) { + .subset2(.input, "impl")$.values$remove(i) + }) + ) +} + +remove_observers <- function(id, .session) { + invisible( + lapply(grep(paste0(id, "_observer"), names(.session$userData), value = TRUE), + function(i) { + .subset2(.session$userData, i)$destroy() + }) + ) +} + +module_UI <- function(id, ui) { + ns <- NS(id) + div(id = id, ui) +} + shinyServer(function(input, output, session) { + module_stack <- reactiveVal(NULL) + + observe({ + shinyjs::disable("remove_module") + }) + debug <- FALSE bs4dash <- getOption("facile.bs4dash") options(facile.bs4dash = FALSE) @@ -32,8 +61,15 @@ shinyServer(function(input, output, session) { ) }) - observeEvent(input$analysis, { + observeEvent(input$add_module, { req(input$analysis != "none") + + # store the id of the newly added module using the + # value of the actionButton to make it unique + module_id <- paste0("id_", input$add_module) + if (debug) print(paste0("this module is ", module_id)) + module_stack(c(module_id, module_stack())) + ui.content <- analysisUI()("analysis", debug = debug) ui <- tagList( @@ -42,8 +78,26 @@ shinyServer(function(input, output, session) { ui.content ) + ui_with_id <- module_UI(module_id, ui) + ## NOTE: immediate = TRUE is necessary! - insertUI("#here", "afterEnd", ui, immediate = TRUE) + insertUI("#gadget_container", "afterEnd", ui_with_id, immediate = TRUE) + + shinyjs::disable("add_module") + shinyjs::enable("remove_module") + }) + + observeEvent(input$remove_module, { + if (length(module_stack()) > 0) { + if (debug) print(paste0("removing module ", module_stack()[1])) + removeUI(paste0("#", module_stack()[1])) + } + remove_shiny_inputs(module_stack()[1], input) + remove_observers(module_stack()[1], session) + module_stack(module_stack()[-1]) + + shinyjs::enable("add_module") + shinyjs::disable("remove_module") }) ## this logic should be isolated into a function @@ -73,11 +127,12 @@ shinyServer(function(input, output, session) { checkmate::assert_class(fds., "FacileDataStore") checkmate::assert_class(samples., "facile_frame") - FacileShine:::ReactiveFacileDataStore(fds., "ds", samples = samples.) + FacileShine::ReactiveFacileDataStore(fds., "ds", samples = samples.) }) - observe({ + observeEvent(req(input$add_module), { req(input$analysis != "none") + if (debug) print("running analysis") analysis <- callModule(analysisModule(), "analysis", rfds(), debug = debug) }) diff --git a/inst/shiny/sandbox/ui.R b/inst/shiny/sandbox/ui.R index e0f82aa..f1dbfab 100644 --- a/inst/shiny/sandbox/ui.R +++ b/inst/shiny/sandbox/ui.R @@ -7,21 +7,23 @@ shinyUI(fluidPage( sidebarLayout( sidebarPanel(width = 3, - - shinyWidgets::pickerInput("dataset", - "Select a dataset", - choices = "TCGA", - selected = "TCGA" - ), - shinyWidgets::pickerInput("analysis", - "Select an analysis:", - choices = c("none", "fdge", "fpca", "ffsea"), - selected = "none" - ) + shinyjs::useShinyjs(), + shinyWidgets::pickerInput("dataset", + "Select a dataset", + choices = "TCGA", + selected = "TCGA" + ), + shinyWidgets::pickerInput("analysis", + "Select an analysis:", + choices = c("none", "fdge", "fpca", "ffsea"), + selected = "none" + ), + actionButton("add_module", "Add", icon = icon("plus-circle")), + actionButton("remove_module", "Remove", icon = icon("trash-alt")) ), - + mainPanel( - tags$div(id = "here") + tags$div(id = "gadget_container") ) ) )) From e503cdf877b5511531cd14ed6ca5e148f0d2a0bf Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Thu, 5 May 2022 11:07:39 +0930 Subject: [PATCH 03/12] add a running listing of results --- inst/shiny/sandbox/server.R | 6 ++++++ inst/shiny/sandbox/ui.R | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/inst/shiny/sandbox/server.R b/inst/shiny/sandbox/server.R index 1ad3a3d..741760f 100644 --- a/inst/shiny/sandbox/server.R +++ b/inst/shiny/sandbox/server.R @@ -26,6 +26,7 @@ module_UI <- function(id, ui) { shinyServer(function(input, output, session) { module_stack <- reactiveVal(NULL) + results_stack <- reactiveVal(data.frame(id = integer(), analysis = character())) observe({ shinyjs::disable("remove_module") @@ -134,6 +135,11 @@ shinyServer(function(input, output, session) { req(input$analysis != "none") if (debug) print("running analysis") analysis <- callModule(analysisModule(), "analysis", rfds(), debug = debug) + results_stack(rbind(results_stack(), data.frame(id = input$add_module, type = input$analysis))) + }) + + output$results_list <- renderTable({ + if (NROW(results_stack()) > 0) results_stack() else NULL }) }) diff --git a/inst/shiny/sandbox/ui.R b/inst/shiny/sandbox/ui.R index f1dbfab..221e603 100644 --- a/inst/shiny/sandbox/ui.R +++ b/inst/shiny/sandbox/ui.R @@ -19,7 +19,10 @@ shinyUI(fluidPage( selected = "none" ), actionButton("add_module", "Add", icon = icon("plus-circle")), - actionButton("remove_module", "Remove", icon = icon("trash-alt")) + actionButton("remove_module", "Remove", icon = icon("trash-alt")), + br(), + h4("Results:"), + tableOutput("results_list") ), mainPanel( From 9ac8a595c3311dfe438d5acb8b928c5ab53000e6 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Mon, 9 May 2022 12:26:20 +0930 Subject: [PATCH 04/12] loop outputs as inputs (not quite ready) --- inst/shiny/sandbox/server.R | 34 +++++++++++++++++++++++++--------- inst/shiny/sandbox/ui.R | 4 ++-- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/inst/shiny/sandbox/server.R b/inst/shiny/sandbox/server.R index 741760f..2645872 100644 --- a/inst/shiny/sandbox/server.R +++ b/inst/shiny/sandbox/server.R @@ -26,7 +26,8 @@ module_UI <- function(id, ui) { shinyServer(function(input, output, session) { module_stack <- reactiveVal(NULL) - results_stack <- reactiveVal(data.frame(id = integer(), analysis = character())) + temp_result <- reactiveVal(NULL) + results_stack <- reactiveVal(tibble::tibble(id = character(), analysis = character(), result = list())) observe({ shinyjs::disable("remove_module") @@ -40,7 +41,7 @@ shinyServer(function(input, output, session) { x <- reactive({ switch(req(input$dataset), "TCGA" = FacileData:::exampleFacileDataSet(), - NULL + results_stack()[results_stack()$id == input$dataset, "result", drop = TRUE][[1]] ) }) @@ -104,7 +105,6 @@ shinyServer(function(input, output, session) { ## this logic should be isolated into a function rfds <- reactive({ req(input$analysis != "none") - .x <- x() if (is(.x, "facile_frame")) { fds. <- FacileData::fds(.x) @@ -131,15 +131,31 @@ shinyServer(function(input, output, session) { FacileShine::ReactiveFacileDataStore(fds., "ds", samples = samples.) }) - observeEvent(req(input$add_module), { - req(input$analysis != "none") - if (debug) print("running analysis") - analysis <- callModule(analysisModule(), "analysis", rfds(), debug = debug) - results_stack(rbind(results_stack(), data.frame(id = input$add_module, type = input$analysis))) + module_res <- reactive({ + callModule(analysisModule(), "analysis", rfds(), aresult = rfds(), gdb = reactive(sparrow::exampleGeneSetDb()), debug = debug) + }) + + observeEvent(input$add_module, { + req(module_res()) + result. <- sparrow::failWith(list(), FacileAnalysis::unreact(FacileAnalysis::faro(module_res()))) + # class(result.) <- FacileAnalysis:::classify_as_gadget(result.) + temp_result(result.) + + }, ignoreNULL = TRUE, ignoreInit = TRUE) + + observeEvent(input$remove_module, { + results_stack( + rbind( + results_stack(), + tibble::tibble(id = paste0("result_", input$add_module), analysis = input$analysis, result = list(temp_result())) + ) + ) + + shinyWidgets::updatePickerInput(session, "dataset", choices = c("TCGA", results_stack()$id)) }) output$results_list <- renderTable({ - if (NROW(results_stack()) > 0) results_stack() else NULL + if (NROW(results_stack()) > 0) results_stack()[, c("id", "analysis")] else NULL }) }) diff --git a/inst/shiny/sandbox/ui.R b/inst/shiny/sandbox/ui.R index 221e603..49731da 100644 --- a/inst/shiny/sandbox/ui.R +++ b/inst/shiny/sandbox/ui.R @@ -9,12 +9,12 @@ shinyUI(fluidPage( sidebarPanel(width = 3, shinyjs::useShinyjs(), shinyWidgets::pickerInput("dataset", - "Select a dataset", + "Select an input:", choices = "TCGA", selected = "TCGA" ), shinyWidgets::pickerInput("analysis", - "Select an analysis:", + "Select an output:", choices = c("none", "fdge", "fpca", "ffsea"), selected = "none" ), From fd94bfa6b0e9ad93da099fff787fc9f19b2afa2f Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Wed, 11 May 2022 16:44:38 +0930 Subject: [PATCH 05/12] add filtering as an output general cleanup --- inst/shiny/sandbox/server.R | 79 +++++++++++++++++++++++++++---------- inst/shiny/sandbox/ui.R | 6 +-- 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/inst/shiny/sandbox/server.R b/inst/shiny/sandbox/server.R index 2645872..a3b6751 100644 --- a/inst/shiny/sandbox/server.R +++ b/inst/shiny/sandbox/server.R @@ -26,27 +26,34 @@ module_UI <- function(id, ui) { shinyServer(function(input, output, session) { module_stack <- reactiveVal(NULL) - temp_result <- reactiveVal(NULL) results_stack <- reactiveVal(tibble::tibble(id = character(), analysis = character(), result = list())) observe({ shinyjs::disable("remove_module") }) - debug <- FALSE + ## UI only works with debug = TRUE for some reason (!) + debug <- TRUE bs4dash <- getOption("facile.bs4dash") options(facile.bs4dash = FALSE) on.exit(options(facile.bs4dash = bs4dash)) - x <- reactive({ - switch(req(input$dataset), + x <- eventReactive(input$dataset, { + d <- switch(req(input$dataset), "TCGA" = FacileData:::exampleFacileDataSet(), results_stack()[results_stack()$id == input$dataset, "result", drop = TRUE][[1]] ) + if (is(d, "ReactiveFacileAnalysisResultContainer")) { + .x <- FacileAnalysis::faro(d) + } else { + .x <- d + } + .x }) analysisModule <- reactive({ switch(req(input$analysis), + "filter" = FacileShine::filteredReactiveFacileDataStore, "fdge" = FacileAnalysis::fdgeAnalysis, "fpca" = FacileAnalysis::fpcaAnalysis, "ffsea" = FacileAnalysis::ffseaAnalysis, @@ -56,6 +63,7 @@ shinyServer(function(input, output, session) { analysisUI <- reactive({ switch(req(input$analysis), + "filter" = FacileShine::filteredReactiveFacileDataStoreUI, "fdge" = FacileAnalysis::fdgeAnalysisUI, "fpca" = FacileAnalysis::fpcaAnalysisUI, "ffsea" = FacileAnalysis::ffseaAnalysisUI, @@ -72,11 +80,9 @@ shinyServer(function(input, output, session) { if (debug) print(paste0("this module is ", module_id)) module_stack(c(module_id, module_stack())) - ui.content <- analysisUI()("analysis", debug = debug) + ui.content <- analysisUI()(ifelse(isolate(req(input$analysis)) == "filter","ds","analysis"), debug = debug) ui <- tagList( - FacileShine::filteredReactiveFacileDataStoreUI("ds"), - tags$hr(), ui.content ) @@ -87,11 +93,15 @@ shinyServer(function(input, output, session) { shinyjs::disable("add_module") shinyjs::enable("remove_module") + + isolate(module_res()) }) observeEvent(input$remove_module, { - if (length(module_stack()) > 0) { - if (debug) print(paste0("removing module ", module_stack()[1])) + if (NROW(req(module_stack())) > 0) { + if (debug) { + print(paste0("removing module ", module_stack()[1])) + } removeUI(paste0("#", module_stack()[1])) } remove_shiny_inputs(module_stack()[1], input) @@ -104,58 +114,85 @@ shinyServer(function(input, output, session) { ## this logic should be isolated into a function rfds <- reactive({ + req(input$dataset) req(input$analysis != "none") + .x <- x() if (is(.x, "facile_frame")) { + if (debug) print("facile_frame") fds. <- FacileData::fds(.x) samples. <- .x sample.filter <- FALSE restrict_samples <- samples. + } else if (is(.x, "ReactiveFacileDataStore")) { + if (debug) print("reactivefaciledatastore") + fds. <- .x$.state$fds + samples. <- .x$.state$active_samples } else if (is(.x, "FacileDataStore")) { + if (debug) print("facileDataStore") sample.filter <- TRUE fds. <- .x samples. <- dplyr::collect(FacileData::samples(.x), n = Inf) } else if (is(.x, "FacileAnalysisResult")) { + if (debug) print("facileAnalysisResult") # ugh, this isn't going to work -- I'm writing this in to fire up a # ffseaGadget, whose needs to be a FacileAnalysisResult. sample.filter <- FALSE - fds. <- FacileData::fds(.x) + fds. <- FacileData::fds(.x[["fds"]]) samples. <- dplyr::collect(FacileData::samples(.x), n = Inf) restrict_samples <- samples. + } else if (is(.x, "ReactiveFacileAnalysisResultContainer")) { + if (debug) print("result container") + fds. <- .x + samples. <- dplyr::collect(FacileData::samples(fds.), n = Inf) } else { stop("What in the world?") } checkmate::assert_class(fds., "FacileDataStore") checkmate::assert_class(samples., "facile_frame") - + FacileShine::ReactiveFacileDataStore(fds., "ds", samples = samples.) }) module_res <- reactive({ - callModule(analysisModule(), "analysis", rfds(), aresult = rfds(), gdb = reactive(sparrow::exampleGeneSetDb()), debug = debug) + res <- callModule(analysisModule(), + id = ifelse(req(input$analysis) == "filter", "ds", "analysis"), + rfds = rfds(), + aresult = x(), + gdb = reactive({sparrow::exampleGeneSetDb()}), + path= reactive(rfds()[["parent.dir"]]), + debug = debug + ) + if (req(input$analysis) == "filter") { + return(rfds()) + } else { + return(res) + } }) observeEvent(input$add_module, { - req(module_res()) - result. <- sparrow::failWith(list(), FacileAnalysis::unreact(FacileAnalysis::faro(module_res()))) - # class(result.) <- FacileAnalysis:::classify_as_gadget(result.) - temp_result(result.) - - }, ignoreNULL = TRUE, ignoreInit = TRUE) + input$dataset + req(input$analysis != "none") + module_res() + }) observeEvent(input$remove_module, { results_stack( rbind( results_stack(), - tibble::tibble(id = paste0("result_", input$add_module), analysis = input$analysis, result = list(temp_result())) + tibble::tibble(id = paste0("result_", input$add_module), analysis = input$analysis, result = list(req(module_res()))) ) ) + if (debug) { + print("results stack:") + print(results_stack()) + } - shinyWidgets::updatePickerInput(session, "dataset", choices = c("TCGA", results_stack()$id)) + shinyWidgets::updatePickerInput(session, "dataset", choices = c("TCGA", results_stack()$id), selected = input$dataset) }) output$results_list <- renderTable({ - if (NROW(results_stack()) > 0) results_stack()[, c("id", "analysis")] else NULL + results_stack()[, c("id", "analysis")] }) }) diff --git a/inst/shiny/sandbox/ui.R b/inst/shiny/sandbox/ui.R index 49731da..8fd2e67 100644 --- a/inst/shiny/sandbox/ui.R +++ b/inst/shiny/sandbox/ui.R @@ -10,16 +10,16 @@ shinyUI(fluidPage( shinyjs::useShinyjs(), shinyWidgets::pickerInput("dataset", "Select an input:", - choices = "TCGA", + choices = c("TCGA"), selected = "TCGA" ), shinyWidgets::pickerInput("analysis", "Select an output:", - choices = c("none", "fdge", "fpca", "ffsea"), + choices = c("none", "filter", "fdge", "fpca", "ffsea"), selected = "none" ), actionButton("add_module", "Add", icon = icon("plus-circle")), - actionButton("remove_module", "Remove", icon = icon("trash-alt")), + actionButton("remove_module", "Done", icon = icon("check-circle")), br(), h4("Results:"), tableOutput("results_list") From 7a188cbfa0ed67276b8f1625b97ac49d992f3142 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Thu, 12 May 2022 11:22:29 +0930 Subject: [PATCH 06/12] store faro results where possible --- inst/shiny/sandbox/server.R | 47 ++++++++++--------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/inst/shiny/sandbox/server.R b/inst/shiny/sandbox/server.R index a3b6751..c7e207e 100644 --- a/inst/shiny/sandbox/server.R +++ b/inst/shiny/sandbox/server.R @@ -39,16 +39,10 @@ shinyServer(function(input, output, session) { on.exit(options(facile.bs4dash = bs4dash)) x <- eventReactive(input$dataset, { - d <- switch(req(input$dataset), + switch(req(input$dataset), "TCGA" = FacileData:::exampleFacileDataSet(), results_stack()[results_stack()$id == input$dataset, "result", drop = TRUE][[1]] ) - if (is(d, "ReactiveFacileAnalysisResultContainer")) { - .x <- FacileAnalysis::faro(d) - } else { - .x <- d - } - .x }) analysisModule <- reactive({ @@ -118,36 +112,14 @@ shinyServer(function(input, output, session) { req(input$analysis != "none") .x <- x() - if (is(.x, "facile_frame")) { - if (debug) print("facile_frame") - fds. <- FacileData::fds(.x) - samples. <- .x - sample.filter <- FALSE - restrict_samples <- samples. - } else if (is(.x, "ReactiveFacileDataStore")) { - if (debug) print("reactivefaciledatastore") + if (is(.x, "ReactiveFacileDataStore")) { fds. <- .x$.state$fds samples. <- .x$.state$active_samples - } else if (is(.x, "FacileDataStore")) { - if (debug) print("facileDataStore") - sample.filter <- TRUE - fds. <- .x - samples. <- dplyr::collect(FacileData::samples(.x), n = Inf) - } else if (is(.x, "FacileAnalysisResult")) { - if (debug) print("facileAnalysisResult") - # ugh, this isn't going to work -- I'm writing this in to fire up a - # ffseaGadget, whose needs to be a FacileAnalysisResult. - sample.filter <- FALSE - fds. <- FacileData::fds(.x[["fds"]]) - samples. <- dplyr::collect(FacileData::samples(.x), n = Inf) - restrict_samples <- samples. - } else if (is(.x, "ReactiveFacileAnalysisResultContainer")) { - if (debug) print("result container") - fds. <- .x - samples. <- dplyr::collect(FacileData::samples(fds.), n = Inf) } else { - stop("What in the world?") + fds. <- FacileData::fds(.x) + samples. <- dplyr::collect(FacileData::samples(.x), n = Inf) } + checkmate::assert_class(fds., "FacileDataStore") checkmate::assert_class(samples., "facile_frame") @@ -177,10 +149,17 @@ shinyServer(function(input, output, session) { }) observeEvent(input$remove_module, { + + if (is(req(module_res()), "ReactiveFacileDataStore")) { + res <- module_res() + } else { + res <- FacileAnalysis::faro(module_res()) + } + results_stack( rbind( results_stack(), - tibble::tibble(id = paste0("result_", input$add_module), analysis = input$analysis, result = list(req(module_res()))) + tibble::tibble(id = paste0("result_", input$add_module), analysis = input$analysis, result = list(res)) ) ) if (debug) { From a6510c40066ea399615570b33818cedddc2bc407 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Thu, 12 May 2022 11:47:31 +0930 Subject: [PATCH 07/12] adding myself as a contributor version bump --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 669a8d2..1dd03bf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,10 +1,11 @@ Package: FacileIncubator Type: Package Title: Incubator for half-baked ideas -Version: 0.0.8 +Version: 0.0.9 Authors@R: c( person("Steve", "Lianoglou", , "lianoglou@dnli.com", c("aut", "cre"), comment = c(ORCID = "0000-0002-0924-1754")), + person("Jonathan", "Carroll", email = "rpkg@jcarroll.com.au", role = c("ctb"), comment = c(ORCID = "0000-0002-1404-5264")), person("Denali Therapeutics", role = c("cph", "fnd"))) Description: This is a safe place to develop half-baked ideas that are surely destined for greatness someday. From c1d3029897dfa5935c5ed2a09e12909b315a73dc Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Thu, 12 May 2022 11:52:03 +0930 Subject: [PATCH 08/12] no need for special treatment of ReactiveFacileDataStore --- inst/shiny/sandbox/server.R | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/inst/shiny/sandbox/server.R b/inst/shiny/sandbox/server.R index c7e207e..926964c 100644 --- a/inst/shiny/sandbox/server.R +++ b/inst/shiny/sandbox/server.R @@ -112,13 +112,8 @@ shinyServer(function(input, output, session) { req(input$analysis != "none") .x <- x() - if (is(.x, "ReactiveFacileDataStore")) { - fds. <- .x$.state$fds - samples. <- .x$.state$active_samples - } else { - fds. <- FacileData::fds(.x) - samples. <- dplyr::collect(FacileData::samples(.x), n = Inf) - } + fds. <- FacileData::fds(.x) + samples. <- dplyr::collect(FacileData::samples(.x), n = Inf) checkmate::assert_class(fds., "FacileDataStore") checkmate::assert_class(samples., "facile_frame") From 991d1c7386f8b4654649de3956ff0f76be944ca7 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Thu, 12 May 2022 15:21:53 +0930 Subject: [PATCH 09/12] don't run analysisModule() for filter; already run RFDS() - prevents doubling of filters --- inst/shiny/sandbox/server.R | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/inst/shiny/sandbox/server.R b/inst/shiny/sandbox/server.R index 926964c..6049789 100644 --- a/inst/shiny/sandbox/server.R +++ b/inst/shiny/sandbox/server.R @@ -74,12 +74,13 @@ shinyServer(function(input, output, session) { if (debug) print(paste0("this module is ", module_id)) module_stack(c(module_id, module_stack())) - ui.content <- analysisUI()(ifelse(isolate(req(input$analysis)) == "filter","ds","analysis"), debug = debug) + context_id <- ifelse(isolate(req(input$analysis)) == "filter", "rfds", "analysis") + ui.content <- analysisUI()(context_id, debug = debug) ui <- tagList( ui.content ) - + ui_with_id <- module_UI(module_id, ui) ## NOTE: immediate = TRUE is necessary! @@ -118,22 +119,21 @@ shinyServer(function(input, output, session) { checkmate::assert_class(fds., "FacileDataStore") checkmate::assert_class(samples., "facile_frame") - FacileShine::ReactiveFacileDataStore(fds., "ds", samples = samples.) + FacileShine::ReactiveFacileDataStore(fds., "rfds", samples = samples., debug = debug) }) module_res <- reactive({ - res <- callModule(analysisModule(), - id = ifelse(req(input$analysis) == "filter", "ds", "analysis"), - rfds = rfds(), - aresult = x(), - gdb = reactive({sparrow::exampleGeneSetDb()}), - path= reactive(rfds()[["parent.dir"]]), - debug = debug - ) if (req(input$analysis) == "filter") { - return(rfds()) + rfds() } else { - return(res) + callModule(analysisModule(), + id = "analysis", + rfds = rfds(), + aresult = x(), + gdb = reactive({sparrow::exampleGeneSetDb()}), + path= reactive(rfds()[["parent.dir"]]), + debug = debug + ) } }) From 7c4dbce3f840543e15456944320d83267e17a643 Mon Sep 17 00:00:00 2001 From: Steve Lianoglou Date: Wed, 11 May 2022 23:03:10 -0700 Subject: [PATCH 10/12] Uses `FacileShine::active_samples()` input came from a filtering function. Just realized that calling `samples()` on a FilteredReactiveFacileDataStore is getting you the universe, not the filtered subset [I do believe]. --- inst/shiny/sandbox/server.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/inst/shiny/sandbox/server.R b/inst/shiny/sandbox/server.R index 6049789..f76fe2c 100644 --- a/inst/shiny/sandbox/server.R +++ b/inst/shiny/sandbox/server.R @@ -114,7 +114,13 @@ shinyServer(function(input, output, session) { .x <- x() fds. <- FacileData::fds(.x) - samples. <- dplyr::collect(FacileData::samples(.x), n = Inf) + + if (is(fds., "BoxedFacileDataStore")) { + samples. <- FacileShine::active_samples(.x) + } else { + samples. <- FacileData::samples(.x) + } + samples. <- dplyr::collect(samples., n= Inf) checkmate::assert_class(fds., "FacileDataStore") checkmate::assert_class(samples., "facile_frame") From 1221c0256d28f7bdf338e2c59c27e04ee57d8b26 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Fri, 13 May 2022 07:21:19 +0930 Subject: [PATCH 11/12] use existing filteredReactiveFacileDataStore invocation coming from ReactiveFacileDataStore use active_samples --- inst/shiny/sandbox/server.R | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/inst/shiny/sandbox/server.R b/inst/shiny/sandbox/server.R index 6049789..5b17ffb 100644 --- a/inst/shiny/sandbox/server.R +++ b/inst/shiny/sandbox/server.R @@ -73,15 +73,13 @@ shinyServer(function(input, output, session) { module_id <- paste0("id_", input$add_module) if (debug) print(paste0("this module is ", module_id)) module_stack(c(module_id, module_stack())) - - context_id <- ifelse(isolate(req(input$analysis)) == "filter", "rfds", "analysis") - ui.content <- analysisUI()(context_id, debug = debug) - - ui <- tagList( - ui.content + + ui_with_id <- module_UI( + module_id, + tagList( + analysisUI()("analysis", debug = debug) + ) ) - - ui_with_id <- module_UI(module_id, ui) ## NOTE: immediate = TRUE is necessary! insertUI("#gadget_container", "afterEnd", ui_with_id, immediate = TRUE) @@ -114,17 +112,29 @@ shinyServer(function(input, output, session) { .x <- x() fds. <- FacileData::fds(.x) - samples. <- dplyr::collect(FacileData::samples(.x), n = Inf) + + if (is(fds., "BoxedFacileDataStore")) { + samples. <- FacileShine::active_samples(.x) + } else { + samples. <- FacileData::samples(.x) + } + samples. <- dplyr::collect(samples., n= Inf) checkmate::assert_class(fds., "FacileDataStore") checkmate::assert_class(samples., "facile_frame") - FacileShine::ReactiveFacileDataStore(fds., "rfds", samples = samples., debug = debug) + FacileShine::ReactiveFacileDataStore(fds., "analysis", samples = samples., debug = debug) }) module_res <- reactive({ if (req(input$analysis) == "filter") { rfds() + # callModule(analysisModule(), + # id = "analysis", + # gdb = reactive({sparrow::exampleGeneSetDb()}), + # path= reactive(FacileData::fds(x())[["parent.dir"]]), + # debug = debug + # ) } else { callModule(analysisModule(), id = "analysis", From a504cf7152e6c423588502831c889889451fc400 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Fri, 13 May 2022 07:25:44 +0930 Subject: [PATCH 12/12] cleanup --- inst/shiny/sandbox/server.R | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/inst/shiny/sandbox/server.R b/inst/shiny/sandbox/server.R index 5b17ffb..abb13be 100644 --- a/inst/shiny/sandbox/server.R +++ b/inst/shiny/sandbox/server.R @@ -26,7 +26,13 @@ module_UI <- function(id, ui) { shinyServer(function(input, output, session) { module_stack <- reactiveVal(NULL) - results_stack <- reactiveVal(tibble::tibble(id = character(), analysis = character(), result = list())) + results_stack <- reactiveVal( + tibble::tibble( + id = character(), + analysis = character(), + result = list() + ) + ) observe({ shinyjs::disable("remove_module") @@ -129,12 +135,6 @@ shinyServer(function(input, output, session) { module_res <- reactive({ if (req(input$analysis) == "filter") { rfds() - # callModule(analysisModule(), - # id = "analysis", - # gdb = reactive({sparrow::exampleGeneSetDb()}), - # path= reactive(FacileData::fds(x())[["parent.dir"]]), - # debug = debug - # ) } else { callModule(analysisModule(), id = "analysis", @@ -164,7 +164,11 @@ shinyServer(function(input, output, session) { results_stack( rbind( results_stack(), - tibble::tibble(id = paste0("result_", input$add_module), analysis = input$analysis, result = list(res)) + tibble::tibble( + id = paste0("result_", input$add_module), + analysis = input$analysis, + result = list(res) + ) ) ) if (debug) { @@ -172,7 +176,11 @@ shinyServer(function(input, output, session) { print(results_stack()) } - shinyWidgets::updatePickerInput(session, "dataset", choices = c("TCGA", results_stack()$id), selected = input$dataset) + shinyWidgets::updatePickerInput( + session, "dataset", + choices = c("TCGA", results_stack()$id), + selected = input$dataset + ) }) output$results_list <- renderTable({