From 6fb3af1d407616c09a790a2280ca6fdd96a1aaa2 Mon Sep 17 00:00:00 2001 From: Vedha Viyash <49812166+vedhav@users.noreply.github.com> Date: Fri, 8 Dec 2023 19:09:53 +0530 Subject: [PATCH] Using `teal_data` in the modules instead of `tdata` (#344) --------- Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Aleksander Chlebowski <114988527+chlebowa@users.noreply.github.com> Co-authored-by: unknown --- DESCRIPTION | 4 ++-- NEWS.md | 1 + R/adtteSpec.R | 27 +++++++++++++++++---------- R/argument_convention.R | 6 +++--- R/assaySpec.R | 24 +++++++++++------------- R/barplot.R | 9 ++++++--- R/boxplot.R | 9 ++++++--- R/experimentSpec.R | 7 ++++--- R/forestplot.R | 9 ++++++--- R/geneSpec.R | 8 ++++---- R/km.R | 10 ++++++---- R/pca.R | 11 ++++++----- R/quality.R | 9 ++++++--- R/sampleVarSpec.R | 24 +++++++++++++++--------- R/scatterplot.R | 9 ++++++--- R/volcanoplot.R | 10 ++++++---- man/adtteSpecServer.Rd | 27 ++++++++++++++++----------- man/assaySpecServer.Rd | 24 +++++++++++------------- man/experimentSpecInput.Rd | 6 +++--- man/experimentSpecServer.Rd | 6 +++--- man/geneSpecServer.Rd | 8 ++++---- man/module_arguments.Rd | 6 +++--- man/sampleVarSpecServer.Rd | 24 +++++++++++++++--------- man/tm_g_barplot.Rd | 8 ++++---- man/tm_g_boxplot.Rd | 8 ++++---- man/tm_g_forest_tte.Rd | 7 +++---- man/tm_g_km.Rd | 8 ++++---- man/tm_g_pca.Rd | 8 ++++---- man/tm_g_quality.Rd | 8 ++++---- man/tm_g_scatterplot.Rd | 8 ++++---- man/tm_g_volcanoplot.Rd | 8 ++++---- tests/testthat/geneSpec/app.R | 2 +- tests/testthat/test-barplot.R | 3 +-- tests/testthat/test-boxplot.R | 3 +-- tests/testthat/test-experimentSpec.R | 24 +++++++++++++++--------- tests/testthat/test-forest.R | 3 +-- tests/testthat/test-km.R | 3 +-- tests/testthat/test-pca.R | 3 +-- tests/testthat/test-quality.R | 3 +-- tests/testthat/test-scatterplot.R | 3 +-- tests/testthat/test-volcanoplot.R | 1 - vignettes/Getting_Started.Rmd | 19 +++++++++---------- 42 files changed, 223 insertions(+), 185 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 000f92bd..c1f33cbd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,7 +30,7 @@ Depends: ggplot2, R (>= 3.6), shiny, - teal (>= 0.14.0.9019) + teal (>= 0.14.0.9027) Imports: checkmate, DT, @@ -47,7 +47,7 @@ Imports: stats, stringr, SummarizedExperiment, - teal.data (>= 0.3.0.9010), + teal.data (>= 0.3.0.9018), teal.logger (>= 0.1.1), teal.reporter (>= 0.2.0), teal.widgets (>= 0.4.0), diff --git a/NEWS.md b/NEWS.md index a5299c19..e45c5193 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ ### Miscellaneous * Added placeholders for `assaySpec`, `adtteSpec` and `geneSpec` inputs when no option is selected. * Disabled the select input for `assaySpec` and `adtteSpec` when there are no options available. +* For module developers: The module gets `teal_data` object in the UI and `reactive()` in the server ### Enhancements diff --git a/R/adtteSpec.R b/R/adtteSpec.R index 1d1d97aa..3ca396ed 100644 --- a/R/adtteSpec.R +++ b/R/adtteSpec.R @@ -148,23 +148,27 @@ adtteSpecInput <- function(inputId, # nolint #' @export #' #' @examples -#' ui <- function(id, -#' data) { +#' ui <- function(id) { #' ns <- NS(id) #' #' teal.widgets::standard_layout( -#' encoding = div( -#' experimentSpecInput(ns("experiment"), data = data, mae_name = "MAE"), -#' assaySpecInput(ns("assay")), -#' geneSpecInput(ns("genes"), funs = list(Mean = colMeans)), -#' adtteSpecInput(ns("adtte")) -#' ), +#' encoding = uiOutput(ns("encoding_ui")), #' output = verbatimTextOutput(ns("summary")) #' ) #' } #' #' server <- function(id, data, filter_panel_api) { +#' checkmate::assert_class(data, "reactive") +#' checkmate::assert_class(shiny::isolate(data()), "teal_data") #' moduleServer(id, function(input, output, session) { +#' output$encoding_ui <- renderUI({ +#' div( +#' experimentSpecInput(session$ns("experiment"), data, mae_name = "MAE"), +#' assaySpecInput(session$ns("assay")), +#' geneSpecInput(session$ns("genes"), funs = list(Mean = colMeans)), +#' adtteSpecInput(session$ns("adtte")) +#' ) +#' }) #' experiment <- experimentSpecServer( #' "experiment", #' data = data, @@ -210,6 +214,7 @@ adtteSpecInput <- function(inputId, # nolint #' my_app <- function() { #' data <- teal_data() #' data <- within(data, { +#' ADSL <- teal.data::rADSL #' ADTTE <- teal.modules.hermes::rADTTE %>% #' dplyr::mutate(is_event = .data$CNSR == 0) #' MAE <- hermes::multi_assay_experiment @@ -254,6 +259,8 @@ adtteSpecServer <- function(id, # nolint assert_reactive(assay) assert_reactive(genes) assert_reactive(probs) + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { # Join ADTTE with gene data. @@ -271,8 +278,8 @@ adtteSpecServer <- function(id, # nolint assay ) - mae <- data[[mae_name]]() - adtte <- data[[adtte_name]]() + mae <- data()[[mae_name]] + adtte <- data()[[adtte_name]] mae[[experiment_name]] <- experiment_data h_km_mae_to_adtte( diff --git a/R/argument_convention.R b/R/argument_convention.R index ad264677..11324bf2 100644 --- a/R/argument_convention.R +++ b/R/argument_convention.R @@ -5,9 +5,9 @@ #' The documentation to this function lists all the conventional arguments in #' `hermes` teal modules. #' -#' @param data (`tdata`)\cr -#' `tdata` object which is automatically passed to the UI and server -#' functions, holding all the data sets provided in the app initialization. +#' @param data (`reactive`)\cr +#' `reactive()` holding all the data sets provided +#' during app initialization after going through the filters. #' @param label (`string`)\cr #' menu item label of the module in the teal app. #' @param inputId (`string`)\cr diff --git a/R/assaySpec.R b/R/assaySpec.R index df4122ce..60770b36 100644 --- a/R/assaySpec.R +++ b/R/assaySpec.R @@ -44,27 +44,25 @@ assaySpecInput <- function(inputId, # nolint #' @export #' #' @examples -#' ui <- function(id, -#' data) { +#' ui <- function(id) { #' ns <- NS(id) #' teal.widgets::standard_layout( -#' encoding = div( -#' experimentSpecInput( -#' ns("experiment"), -#' data, -#' "MAE" -#' ), -#' assaySpecInput( -#' ns("assay"), -#' label_assays = "Please choose assay" -#' ) -#' ), +#' encoding = uiOutput(ns("encoding_ui")), #' output = textOutput(ns("result")) #' ) #' } #' #' server <- function(id, data, filter_panel_api) { #' moduleServer(id, module = function(input, output, session) { +#' output$encoding_ui <- renderUI({ +#' div( +#' experimentSpecInput(session$ns("experiment"), data, "MAE"), +#' assaySpecInput( +#' session$ns("assay"), +#' label_assays = "Please choose assay" +#' ) +#' ) +#' }) #' experiment <- experimentSpecServer( #' id = "experiment", #' data = data, diff --git a/R/barplot.R b/R/barplot.R index a9946174..0f6e4595 100644 --- a/R/barplot.R +++ b/R/barplot.R @@ -66,7 +66,6 @@ tm_g_barplot <- function(label, #' @inheritParams module_arguments #' @export ui_g_barplot <- function(id, - data, mae_name, summary_funs, pre_output, @@ -79,7 +78,7 @@ ui_g_barplot <- function(id, ### tags$label("Encodings", class = "text-primary"), helpText("Analysis of MAE:", tags$code(mae_name)), - experimentSpecInput(ns("experiment"), data, mae_name), + uiOutput(ns("experiment_ui")), assaySpecInput(ns("assay")), sampleVarSpecInput(ns("facet"), "Select Facet Variable"), geneSpecInput(ns("x"), summary_funs), @@ -120,8 +119,12 @@ srv_g_barplot <- function(id, summary_funs) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") assert_class(filter_panel_api, "FilterPanelAPI") - assert_class(data, "tdata") + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + output$experiment_ui <- renderUI({ + experimentSpecInput(session$ns("experiment"), data, mae_name) + }) experiment <- experimentSpecServer( "experiment", data = data, diff --git a/R/boxplot.R b/R/boxplot.R index ac703eee..4057a61b 100644 --- a/R/boxplot.R +++ b/R/boxplot.R @@ -67,7 +67,6 @@ tm_g_boxplot <- function(label, #' @inheritParams module_arguments #' @export ui_g_boxplot <- function(id, - data, mae_name, summary_funs, pre_output, @@ -80,7 +79,7 @@ ui_g_boxplot <- function(id, ### tags$label("Encodings", class = "text-primary"), helpText("Analysis of MAE:", tags$code(mae_name)), - experimentSpecInput(ns("experiment"), data, mae_name), + uiOutput(ns("experiment_ui")), assaySpecInput(ns("assay")), geneSpecInput(ns("genes"), summary_funs), tags$label("Jitter"), @@ -116,9 +115,13 @@ srv_g_boxplot <- function(id, summary_funs) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") assert_class(filter_panel_api, "FilterPanelAPI") - assert_class(data, "tdata") + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + output$experiment_ui <- renderUI({ + experimentSpecInput(session$ns("experiment"), data, mae_name) + }) experiment <- experimentSpecServer( "experiment", data = data, diff --git a/R/experimentSpec.R b/R/experimentSpec.R index 8963578c..700e768a 100644 --- a/R/experimentSpec.R +++ b/R/experimentSpec.R @@ -17,7 +17,7 @@ experimentSpecInput <- function(inputId, # nolint assert_string(inputId) assert_string(mae_name, min.chars = 1L) assert_string(label_experiments, min.chars = 1L) - mae <- data[[mae_name]]() + mae <- data()[[mae_name]] name_choices <- names(mae) ns <- NS(inputId) @@ -210,7 +210,8 @@ experimentSpecServer <- function(id, # nolint sample_vars_as_factors = TRUE, with_mae_col_data = TRUE) { assert_string(id) - assert_class(data, "tdata") + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") assert_string(mae_name, min.chars = 1L) assert_string(name_annotation, min.chars = 1L, null.ok = TRUE) assert_flag(sample_vars_as_factors) @@ -222,7 +223,7 @@ experimentSpecServer <- function(id, # nolint data_return <- reactive({ name <- input$name req(name) - mae <- data[[mae_name]]() + mae <- data()[[mae_name]] orig_object <- mae[[name]] validate(need( hermes::is_hermes_data(orig_object), diff --git a/R/forestplot.R b/R/forestplot.R index 3b9c0625..3e9665cc 100644 --- a/R/forestplot.R +++ b/R/forestplot.R @@ -92,7 +92,6 @@ tm_g_forest_tte <- function(label, #' @inheritParams module_arguments #' @export ui_g_forest_tte <- function(id, - data, adtte_name, mae_name, summary_funs, @@ -106,7 +105,7 @@ ui_g_forest_tte <- function(id, ### tags$label("Encodings", class = "text-primary"), helpText("Analysis of MAE:", tags$code(mae_name)), - experimentSpecInput(ns("experiment"), data, mae_name), + uiOutput(ns("experiment_ui")), assaySpecInput(ns("assay")), geneSpecInput(ns("genes"), summary_funs), helpText("Analysis of ADTTE:", tags$code(adtte_name)), @@ -143,9 +142,13 @@ srv_g_forest_tte <- function(id, plot_width) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") assert_class(filter_panel_api, "FilterPanelAPI") - assert_class(data, "tdata") + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + output$experiment_ui <- renderUI({ + experimentSpecInput(session$ns("experiment"), data, mae_name) + }) experiment <- experimentSpecServer( "experiment", data = data, diff --git a/R/geneSpec.R b/R/geneSpec.R index 77239bc8..522fb8ea 100644 --- a/R/geneSpec.R +++ b/R/geneSpec.R @@ -219,9 +219,7 @@ h_parse_genes <- function(words, choices) { #' @export #' #' @examples -#' ui <- function(id, -#' data, -#' funs) { +#' ui <- function(id, funs) { #' ns <- NS(id) #' teal.widgets::standard_layout( #' encoding = div( @@ -237,9 +235,11 @@ h_parse_genes <- function(words, choices) { #' server <- function(id, #' data, #' funs) { +#' checkmate::assert_class(data, "reactive") +#' checkmate::assert_class(shiny::isolate(data()), "teal_data") #' moduleServer(id, function(input, output, session) { #' gene_choices <- reactive({ -#' mae <- data[["MAE"]]() +#' mae <- data()[["MAE"]] #' object <- mae[[1]] #' gene_ids <- rownames(object) #' gene_names <- SummarizedExperiment::rowData(object)$symbol diff --git a/R/km.R b/R/km.R index 0da8f8b5..06f46833 100644 --- a/R/km.R +++ b/R/km.R @@ -93,14 +93,12 @@ tm_g_km <- function(label, #' @inheritParams module_arguments #' @export ui_g_km <- function(id, - data, adtte_name, mae_name, summary_funs, pre_output, post_output) { ns <- NS(id) - teal.widgets::standard_layout( encoding = div( ### Reporter @@ -108,7 +106,7 @@ ui_g_km <- function(id, ### tags$label("Encodings", class = "text-primary"), helpText("Analysis of MAE:", tags$code(mae_name)), - experimentSpecInput(ns("experiment"), data, mae_name), + uiOutput(ns("experiment_ui")), assaySpecInput(ns("assay")), geneSpecInput(ns("genes"), summary_funs), helpText("Analysis of ADTTE:", tags$code(adtte_name)), @@ -149,9 +147,13 @@ srv_g_km <- function(id, exclude_assays) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") assert_class(filter_panel_api, "FilterPanelAPI") - assert_class(data, "tdata") + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + output$experiment_ui <- renderUI({ + experimentSpecInput(session$ns("experiment"), data, mae_name) + }) experiment <- experimentSpecServer( "experiment", data = data, diff --git a/R/pca.R b/R/pca.R index 787c015e..4c07acf5 100644 --- a/R/pca.R +++ b/R/pca.R @@ -57,13 +57,10 @@ tm_g_pca <- function(label, #' @inheritParams module_arguments #' @export ui_g_pca <- function(id, - data, mae_name, pre_output, post_output) { ns <- NS(id) - mae <- data[[mae_name]]() - experiment_name_choices <- names(mae) tagList( teal.widgets::standard_layout( @@ -74,7 +71,7 @@ ui_g_pca <- function(id, ### tags$label("Encodings", class = "text-primary"), helpText("Analysis of MAE:", tags$code(mae_name)), - experimentSpecInput(ns("experiment"), data, mae_name), + uiOutput(ns("experiment_ui")), assaySpecInput(ns("assay")), conditionalPanel( condition = "input.tab_selected == 'PCA'", @@ -160,9 +157,13 @@ srv_g_pca <- function(id, exclude_assays) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") assert_class(filter_panel_api, "FilterPanelAPI") - assert_class(data, "tdata") + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + output$experiment_ui <- renderUI({ + experimentSpecInput(session$ns("experiment"), data, mae_name) + }) experiment <- experimentSpecServer( "experiment", data = data, diff --git a/R/quality.R b/R/quality.R index ddae3b69..d2d17f8c 100644 --- a/R/quality.R +++ b/R/quality.R @@ -111,7 +111,6 @@ tm_g_quality <- function(label, #' @inheritParams module_arguments #' @export ui_g_quality <- function(id, - data, mae_name, pre_output, post_output) { @@ -123,7 +122,7 @@ ui_g_quality <- function(id, ### tags$label("Encodings", class = "text-primary"), helpText("Analysis of MAE:", tags$code(mae_name)), - experimentSpecInput(ns("experiment"), data, mae_name), + uiOutput(ns("experiment_ui")), selectInput( ns("plot_type"), "Plot Type", @@ -200,9 +199,13 @@ srv_g_quality <- function(id, exclude_assays) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") assert_class(filter_panel_api, "FilterPanelAPI") - assert_class(data, "tdata") + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + output$experiment_ui <- renderUI({ + experimentSpecInput(session$ns("experiment"), data, mae_name) + }) experiment <- experimentSpecServer( "experiment", data = data, diff --git a/R/sampleVarSpec.R b/R/sampleVarSpec.R index bfd371fc..0aa3f00c 100644 --- a/R/sampleVarSpec.R +++ b/R/sampleVarSpec.R @@ -201,25 +201,31 @@ validate_n_levels <- function(x, name, n_levels) { #' @export #' #' @examples -#' ui <- function(id, -#' data) { +#' ui <- function(id) { +#' checkmate::assert_class(data, "teal_data") #' ns <- NS(id) -#' mae <- data[["MAE"]]() -#' experiment_name_choices <- names(mae) +#' #' teal.widgets::standard_layout( -#' encoding = div( -#' selectInput(ns("experiment_name"), "Select experiment", experiment_name_choices), -#' sampleVarSpecInput(ns("facet_var"), "Select faceting variable") -#' ), +#' encoding = uiOutput(ns("encoding_ui")), #' output = plotOutput(ns("plot")) #' ) #' } #' server <- function(id, #' data) { +#' checkmate::assert_class(data, "reactive") +#' checkmate::assert_class(shiny::isolate(data()), "teal_data") #' moduleServer(id, function(input, output, session) { +#' output$encoding_ui <- renderUI({ +#' mae <- data()[["MAE"]] +#' experiment_name_choices <- names(mae) +#' div( +#' selectInput(session$ns("experiment_name"), "Select experiment", experiment_name_choices), +#' sampleVarSpecInput(session$ns("facet_var"), "Select faceting variable") +#' ) +#' }) #' experiment_data <- reactive({ #' req(input$experiment_name) -#' mae <- data[["MAE"]]() +#' mae <- data()[["MAE"]] #' object <- mae[[input$experiment_name]] #' SummarizedExperiment::colData(object) <- #' hermes::df_cols_to_factor(SummarizedExperiment::colData(object)) diff --git a/R/scatterplot.R b/R/scatterplot.R index e98beff0..42cde8c3 100644 --- a/R/scatterplot.R +++ b/R/scatterplot.R @@ -66,7 +66,6 @@ tm_g_scatterplot <- function(label, #' @inheritParams module_arguments #' @export ui_g_scatterplot <- function(id, - data, mae_name, summary_funs, pre_output, @@ -86,7 +85,7 @@ ui_g_scatterplot <- function(id, ### tags$label("Encodings", class = "text-primary"), helpText("Analysis of MAE:", tags$code(mae_name)), - experimentSpecInput(ns("experiment"), data, mae_name), + uiOutput(ns("experiment_ui")), assaySpecInput(ns("assay")), geneSpecInput(ns("x_spec"), summary_funs, label_genes = "Select x Gene(s)"), geneSpecInput(ns("y_spec"), summary_funs, label_genes = "Select y Gene(s)"), @@ -119,9 +118,13 @@ srv_g_scatterplot <- function(id, summary_funs) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") assert_class(filter_panel_api, "FilterPanelAPI") - assert_class(data, "tdata") + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + output$experiment_ui <- renderUI({ + experimentSpecInput(session$ns("experiment"), data, mae_name) + }) experiment <- experimentSpecServer( "experiment", data = data, diff --git a/R/volcanoplot.R b/R/volcanoplot.R index 3617575c..b9865c88 100644 --- a/R/volcanoplot.R +++ b/R/volcanoplot.R @@ -58,12 +58,10 @@ tm_g_volcanoplot <- function(label, #' @inheritParams module_arguments #' @export ui_g_volcanoplot <- function(id, - data, mae_name, pre_output, post_output) { ns <- NS(id) - mae <- data[[mae_name]] teal.widgets::standard_layout( output = div( @@ -78,7 +76,7 @@ ui_g_volcanoplot <- function(id, ### tags$label("Encodings", class = "text-primary"), helpText("Analysis of MAE:", tags$code(mae_name)), - experimentSpecInput(ns("experiment"), data, mae_name), + uiOutput(ns("experiment_ui")), assaySpecInput(ns("assay")), sampleVarSpecInput(ns("compare_group"), "Compare Groups", "Please group here into 2 levels"), tags$label("Show Top Differentiated Genes"), @@ -108,9 +106,13 @@ srv_g_volcanoplot <- function(id, exclude_assays) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") assert_class(filter_panel_api, "FilterPanelAPI") - assert_class(data, "tdata") + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + output$experiment_ui <- renderUI({ + experimentSpecInput(session$ns("experiment"), data, mae_name) + }) experiment_data <- experimentSpecServer( "experiment", data = data, diff --git a/man/adtteSpecServer.Rd b/man/adtteSpecServer.Rd index 0cd4bdcb..40aaaaed 100644 --- a/man/adtteSpecServer.Rd +++ b/man/adtteSpecServer.Rd @@ -20,9 +20,9 @@ adtteSpecServer( \arguments{ \item{id}{(\code{string}) the shiny module id.} -\item{data}{(\code{tdata})\cr -\code{tdata} object which is automatically passed to the UI and server -functions, holding all the data sets provided in the app initialization.} +\item{data}{(\code{reactive})\cr +\verb{reactive()} holding all the data sets provided +during app initialization after going through the filters.} \item{mae_name}{(\code{string})\cr name of the MAE data used in the teal module.} @@ -74,23 +74,27 @@ and experiment, as numeric and factor columns. The factor column is created by b the numeric column according to the quantile cutoffs specified in \code{probs}. } \examples{ -ui <- function(id, - data) { +ui <- function(id) { ns <- NS(id) teal.widgets::standard_layout( - encoding = div( - experimentSpecInput(ns("experiment"), data = data, mae_name = "MAE"), - assaySpecInput(ns("assay")), - geneSpecInput(ns("genes"), funs = list(Mean = colMeans)), - adtteSpecInput(ns("adtte")) - ), + encoding = uiOutput(ns("encoding_ui")), output = verbatimTextOutput(ns("summary")) ) } server <- function(id, data, filter_panel_api) { + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + output$encoding_ui <- renderUI({ + div( + experimentSpecInput(session$ns("experiment"), data, mae_name = "MAE"), + assaySpecInput(session$ns("assay")), + geneSpecInput(session$ns("genes"), funs = list(Mean = colMeans)), + adtteSpecInput(session$ns("adtte")) + ) + }) experiment <- experimentSpecServer( "experiment", data = data, @@ -136,6 +140,7 @@ server <- function(id, data, filter_panel_api) { my_app <- function() { data <- teal_data() data <- within(data, { + ADSL <- teal.data::rADSL ADTTE <- teal.modules.hermes::rADTTE \%>\% dplyr::mutate(is_event = .data$CNSR == 0) MAE <- hermes::multi_assay_experiment diff --git a/man/assaySpecServer.Rd b/man/assaySpecServer.Rd index 192807eb..77979dfb 100644 --- a/man/assaySpecServer.Rd +++ b/man/assaySpecServer.Rd @@ -23,27 +23,25 @@ The chosen assay as a reactive string. This defines the server part for the assay specification. } \examples{ -ui <- function(id, - data) { +ui <- function(id) { ns <- NS(id) teal.widgets::standard_layout( - encoding = div( - experimentSpecInput( - ns("experiment"), - data, - "MAE" - ), - assaySpecInput( - ns("assay"), - label_assays = "Please choose assay" - ) - ), + encoding = uiOutput(ns("encoding_ui")), output = textOutput(ns("result")) ) } server <- function(id, data, filter_panel_api) { moduleServer(id, module = function(input, output, session) { + output$encoding_ui <- renderUI({ + div( + experimentSpecInput(session$ns("experiment"), data, "MAE"), + assaySpecInput( + session$ns("assay"), + label_assays = "Please choose assay" + ) + ) + }) experiment <- experimentSpecServer( id = "experiment", data = data, diff --git a/man/experimentSpecInput.Rd b/man/experimentSpecInput.Rd index 2d7130c5..26759f2b 100644 --- a/man/experimentSpecInput.Rd +++ b/man/experimentSpecInput.Rd @@ -15,9 +15,9 @@ experimentSpecInput( \item{inputId}{(\code{string})\cr the ID used to call the module input.} -\item{data}{(\code{tdata})\cr -\code{tdata} object which is automatically passed to the UI and server -functions, holding all the data sets provided in the app initialization.} +\item{data}{(\code{reactive})\cr +\verb{reactive()} holding all the data sets provided +during app initialization after going through the filters.} \item{mae_name}{(\code{string})\cr name of the MAE data used in the teal module.} diff --git a/man/experimentSpecServer.Rd b/man/experimentSpecServer.Rd index 5b4554ac..82049188 100644 --- a/man/experimentSpecServer.Rd +++ b/man/experimentSpecServer.Rd @@ -17,9 +17,9 @@ experimentSpecServer( \arguments{ \item{id}{(\code{string}) the shiny module id.} -\item{data}{(\code{tdata})\cr -\code{tdata} object which is automatically passed to the UI and server -functions, holding all the data sets provided in the app initialization.} +\item{data}{(\code{reactive})\cr +\verb{reactive()} holding all the data sets provided +during app initialization after going through the filters.} \item{filter_panel_api}{(\code{FilterPanelAPI})\cr object describing the actual filter panel API.} diff --git a/man/geneSpecServer.Rd b/man/geneSpecServer.Rd index ba91c62c..8ec0e647 100644 --- a/man/geneSpecServer.Rd +++ b/man/geneSpecServer.Rd @@ -36,9 +36,7 @@ Reactive \code{\link[hermes:GeneSpec]{hermes::GeneSpec}} which can be used as in This defines the server part for the gene signature specification. } \examples{ -ui <- function(id, - data, - funs) { +ui <- function(id, funs) { ns <- NS(id) teal.widgets::standard_layout( encoding = div( @@ -54,9 +52,11 @@ ui <- function(id, server <- function(id, data, funs) { + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { gene_choices <- reactive({ - mae <- data[["MAE"]]() + mae <- data()[["MAE"]] object <- mae[[1]] gene_ids <- rownames(object) gene_names <- SummarizedExperiment::rowData(object)$symbol diff --git a/man/module_arguments.Rd b/man/module_arguments.Rd index b0c34675..465c1ed0 100644 --- a/man/module_arguments.Rd +++ b/man/module_arguments.Rd @@ -4,9 +4,9 @@ \alias{module_arguments} \title{Standard Module Arguments} \arguments{ -\item{data}{(\code{tdata})\cr -\code{tdata} object which is automatically passed to the UI and server -functions, holding all the data sets provided in the app initialization.} +\item{data}{(\code{reactive})\cr +\verb{reactive()} holding all the data sets provided +during app initialization after going through the filters.} \item{label}{(\code{string})\cr menu item label of the module in the teal app.} diff --git a/man/sampleVarSpecServer.Rd b/man/sampleVarSpecServer.Rd index 11dc042f..956ff126 100644 --- a/man/sampleVarSpecServer.Rd +++ b/man/sampleVarSpecServer.Rd @@ -58,25 +58,31 @@ which are not completely missing (\code{NA}) will be shown for selection. If \code{num_levels} is specified then only factor columns will be available. } \examples{ -ui <- function(id, - data) { +ui <- function(id) { + checkmate::assert_class(data, "teal_data") ns <- NS(id) - mae <- data[["MAE"]]() - experiment_name_choices <- names(mae) + teal.widgets::standard_layout( - encoding = div( - selectInput(ns("experiment_name"), "Select experiment", experiment_name_choices), - sampleVarSpecInput(ns("facet_var"), "Select faceting variable") - ), + encoding = uiOutput(ns("encoding_ui")), output = plotOutput(ns("plot")) ) } server <- function(id, data) { + checkmate::assert_class(data, "reactive") + checkmate::assert_class(shiny::isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { + output$encoding_ui <- renderUI({ + mae <- data()[["MAE"]] + experiment_name_choices <- names(mae) + div( + selectInput(session$ns("experiment_name"), "Select experiment", experiment_name_choices), + sampleVarSpecInput(session$ns("facet_var"), "Select faceting variable") + ) + }) experiment_data <- reactive({ req(input$experiment_name) - mae <- data[["MAE"]]() + mae <- data()[["MAE"]] object <- mae[[input$experiment_name]] SummarizedExperiment::colData(object) <- hermes::df_cols_to_factor(SummarizedExperiment::colData(object)) diff --git a/man/tm_g_barplot.Rd b/man/tm_g_barplot.Rd index a70d2927..eddfa0e0 100644 --- a/man/tm_g_barplot.Rd +++ b/man/tm_g_barplot.Rd @@ -17,7 +17,7 @@ tm_g_barplot( post_output = NULL ) -ui_g_barplot(id, data, mae_name, summary_funs, pre_output, post_output) +ui_g_barplot(id, mae_name, summary_funs, pre_output, post_output) srv_g_barplot( id, @@ -54,9 +54,9 @@ elements can be useful).} \item{id}{(\code{string}) the shiny module id.} -\item{data}{(\code{tdata})\cr -\code{tdata} object which is automatically passed to the UI and server -functions, holding all the data sets provided in the app initialization.} +\item{data}{(\code{reactive})\cr +\verb{reactive()} holding all the data sets provided +during app initialization after going through the filters.} \item{filter_panel_api}{(\code{FilterPanelAPI})\cr object describing the actual filter panel API.} diff --git a/man/tm_g_boxplot.Rd b/man/tm_g_boxplot.Rd index 3da1f6fe..a5a4dff0 100644 --- a/man/tm_g_boxplot.Rd +++ b/man/tm_g_boxplot.Rd @@ -17,7 +17,7 @@ tm_g_boxplot( post_output = NULL ) -ui_g_boxplot(id, data, mae_name, summary_funs, pre_output, post_output) +ui_g_boxplot(id, mae_name, summary_funs, pre_output, post_output) srv_g_boxplot( id, @@ -54,9 +54,9 @@ elements can be useful).} \item{id}{(\code{string}) the shiny module id.} -\item{data}{(\code{tdata})\cr -\code{tdata} object which is automatically passed to the UI and server -functions, holding all the data sets provided in the app initialization.} +\item{data}{(\code{reactive})\cr +\verb{reactive()} holding all the data sets provided +during app initialization after going through the filters.} \item{filter_panel_api}{(\code{FilterPanelAPI})\cr object describing the actual filter panel API.} diff --git a/man/tm_g_forest_tte.Rd b/man/tm_g_forest_tte.Rd index 03af5e88..f28a15a8 100644 --- a/man/tm_g_forest_tte.Rd +++ b/man/tm_g_forest_tte.Rd @@ -24,7 +24,6 @@ tm_g_forest_tte( ui_g_forest_tte( id, - data, adtte_name, mae_name, summary_funs, @@ -93,9 +92,9 @@ and maximum plot width.} \item{id}{(\code{string}) the shiny module id.} -\item{data}{(\code{tdata})\cr -\code{tdata} object which is automatically passed to the UI and server -functions, holding all the data sets provided in the app initialization.} +\item{data}{(\code{reactive})\cr +\verb{reactive()} holding all the data sets provided +during app initialization after going through the filters.} \item{filter_panel_api}{(\code{FilterPanelAPI})\cr object describing the actual filter panel API.} diff --git a/man/tm_g_km.Rd b/man/tm_g_km.Rd index 9ffcf7f0..acd0392b 100644 --- a/man/tm_g_km.Rd +++ b/man/tm_g_km.Rd @@ -20,7 +20,7 @@ tm_g_km( post_output = NULL ) -ui_g_km(id, data, adtte_name, mae_name, summary_funs, pre_output, post_output) +ui_g_km(id, adtte_name, mae_name, summary_funs, pre_output, post_output) srv_g_km( id, @@ -75,9 +75,9 @@ elements can be useful).} \item{id}{(\code{string}) the shiny module id.} -\item{data}{(\code{tdata})\cr -\code{tdata} object which is automatically passed to the UI and server -functions, holding all the data sets provided in the app initialization.} +\item{data}{(\code{reactive})\cr +\verb{reactive()} holding all the data sets provided +during app initialization after going through the filters.} \item{filter_panel_api}{(\code{FilterPanelAPI})\cr object describing the actual filter panel API.} diff --git a/man/tm_g_pca.Rd b/man/tm_g_pca.Rd index d0a95518..7eae7ac1 100644 --- a/man/tm_g_pca.Rd +++ b/man/tm_g_pca.Rd @@ -15,7 +15,7 @@ tm_g_pca( post_output = NULL ) -ui_g_pca(id, data, mae_name, pre_output, post_output) +ui_g_pca(id, mae_name, pre_output, post_output) srv_g_pca(id, data, filter_panel_api, reporter, mae_name, exclude_assays) @@ -40,9 +40,9 @@ elements can be useful).} \item{id}{(\code{string}) the shiny module id.} -\item{data}{(\code{tdata})\cr -\code{tdata} object which is automatically passed to the UI and server -functions, holding all the data sets provided in the app initialization.} +\item{data}{(\code{reactive})\cr +\verb{reactive()} holding all the data sets provided +during app initialization after going through the filters.} \item{filter_panel_api}{(\code{FilterPanelAPI})\cr object describing the actual filter panel API.} diff --git a/man/tm_g_quality.Rd b/man/tm_g_quality.Rd index f3020027..09851bd3 100644 --- a/man/tm_g_quality.Rd +++ b/man/tm_g_quality.Rd @@ -15,7 +15,7 @@ tm_g_quality( post_output = NULL ) -ui_g_quality(id, data, mae_name, pre_output, post_output) +ui_g_quality(id, mae_name, pre_output, post_output) srv_g_quality(id, data, filter_panel_api, reporter, mae_name, exclude_assays) @@ -40,9 +40,9 @@ elements can be useful).} \item{id}{(\code{string}) the shiny module id.} -\item{data}{(\code{tdata})\cr -\code{tdata} object which is automatically passed to the UI and server -functions, holding all the data sets provided in the app initialization.} +\item{data}{(\code{reactive})\cr +\verb{reactive()} holding all the data sets provided +during app initialization after going through the filters.} \item{filter_panel_api}{(\code{FilterPanelAPI})\cr object describing the actual filter panel API.} diff --git a/man/tm_g_scatterplot.Rd b/man/tm_g_scatterplot.Rd index 5160aeae..f49e3db2 100644 --- a/man/tm_g_scatterplot.Rd +++ b/man/tm_g_scatterplot.Rd @@ -17,7 +17,7 @@ tm_g_scatterplot( post_output = NULL ) -ui_g_scatterplot(id, data, mae_name, summary_funs, pre_output, post_output) +ui_g_scatterplot(id, mae_name, summary_funs, pre_output, post_output) srv_g_scatterplot( id, @@ -54,9 +54,9 @@ elements can be useful).} \item{id}{(\code{string}) the shiny module id.} -\item{data}{(\code{tdata})\cr -\code{tdata} object which is automatically passed to the UI and server -functions, holding all the data sets provided in the app initialization.} +\item{data}{(\code{reactive})\cr +\verb{reactive()} holding all the data sets provided +during app initialization after going through the filters.} \item{filter_panel_api}{(\code{FilterPanelAPI})\cr object describing the actual filter panel API.} diff --git a/man/tm_g_volcanoplot.Rd b/man/tm_g_volcanoplot.Rd index cbf83332..295180aa 100644 --- a/man/tm_g_volcanoplot.Rd +++ b/man/tm_g_volcanoplot.Rd @@ -15,7 +15,7 @@ tm_g_volcanoplot( post_output = NULL ) -ui_g_volcanoplot(id, data, mae_name, pre_output, post_output) +ui_g_volcanoplot(id, mae_name, pre_output, post_output) srv_g_volcanoplot( id, @@ -47,9 +47,9 @@ elements can be useful).} \item{id}{(\code{string}) the shiny module id.} -\item{data}{(\code{tdata})\cr -\code{tdata} object which is automatically passed to the UI and server -functions, holding all the data sets provided in the app initialization.} +\item{data}{(\code{reactive})\cr +\verb{reactive()} holding all the data sets provided +during app initialization after going through the filters.} \item{filter_panel_api}{(\code{FilterPanelAPI})\cr object describing the actual filter panel API.} diff --git a/tests/testthat/geneSpec/app.R b/tests/testthat/geneSpec/app.R index bbcbdb42..f91bb1e1 100644 --- a/tests/testthat/geneSpec/app.R +++ b/tests/testthat/geneSpec/app.R @@ -21,7 +21,7 @@ server <- function(id, funs) { moduleServer(id, function(input, output, session) { gene_choices <- reactive({ - mae <- data[["MAE"]]() + mae <- data()[["MAE"]] object <- mae[[1]] gene_ids <- rownames(object) gene_names <- SummarizedExperiment::rowData(object)$symbol diff --git a/tests/testthat/test-barplot.R b/tests/testthat/test-barplot.R index 02bf88b5..c472a372 100644 --- a/tests/testthat/test-barplot.R +++ b/tests/testthat/test-barplot.R @@ -3,10 +3,9 @@ test_that("ui_g_barplot creates expected HTML", { mae_name <- "MyMAE" set.seed(999) - data <- list(MyMAE = function() hermes::multi_assay_experiment) + data <- teal.data::teal_data(MyMAE = function() hermes::multi_assay_experiment) expect_silent(result <- ui_g_barplot( id = "testid", - data = data, mae_name = mae_name, summary_funs = list( Mean = colMeans diff --git a/tests/testthat/test-boxplot.R b/tests/testthat/test-boxplot.R index a5019fb4..6528e68b 100644 --- a/tests/testthat/test-boxplot.R +++ b/tests/testthat/test-boxplot.R @@ -2,10 +2,9 @@ test_that("ui_g_boxplot creates expected HTML", { mae_name <- "MyMAE" - data <- list(MyMAE = function() hermes::multi_assay_experiment) + data <- teal.data::teal_data(MyMAE = function() hermes::multi_assay_experiment) result <- ui_g_boxplot( id = "testid", - data = data, mae_name = mae_name, summary_funs = list(Mean = colMeans), pre_output = NULL, diff --git a/tests/testthat/test-experimentSpec.R b/tests/testthat/test-experimentSpec.R index 225c4d7f..df04a9b4 100644 --- a/tests/testthat/test-experimentSpec.R +++ b/tests/testthat/test-experimentSpec.R @@ -2,15 +2,21 @@ test_that("experimentSpecInput creates expected HTML", { mae_name <- "MyMAE" set.seed(123) - data <- list(MyMAE = function() hermes::multi_assay_experiment) - expect_silent(result <- experimentSpecInput( - inputId = "my_experiment", - data = data, - mae_name = mae_name, - label_experiments = "Please select the best experiment" - )) - - expect_tag(result) + server <- function(input, output, session) { + data <- reactive(teal_data(MyMAE = hermes::multi_assay_experiment)) + result <- experimentSpecInput( + inputId = "my_experiment", + data = data, + mae_name = mae_name, + label_experiments = "Please select the best experiment" + ) + } + + testServer(server, { + expect_silent( + expect_tag(result) + ) + }) }) # h_order_genes ---- diff --git a/tests/testthat/test-forest.R b/tests/testthat/test-forest.R index 19f5a0f6..8bc67ce0 100644 --- a/tests/testthat/test-forest.R +++ b/tests/testthat/test-forest.R @@ -3,10 +3,9 @@ test_that("ui_g_forest_tte creates expected HTML", { mae_name <- "MyMAE" set.seed(123) - data <- list(MyMAE = function() hermes::multi_assay_experiment) + data <- teal.data::teal_data(MyMAE = function() hermes::multi_assay_experiment) expect_silent(result <- ui_g_forest_tte( id = "testid", - data = data, adtte_name = "ADTTE", mae_name = mae_name, summary_funs = list( diff --git a/tests/testthat/test-km.R b/tests/testthat/test-km.R index 87cce675..7788c006 100644 --- a/tests/testthat/test-km.R +++ b/tests/testthat/test-km.R @@ -3,10 +3,9 @@ test_that("ui_g_km creates expected HTML", { mae_name <- "MyMAE" set.seed(123) - data <- list(MyMAE = function() hermes::multi_assay_experiment) + data <- teal.data::teal_data(MyMAE = function() hermes::multi_assay_experiment) expect_silent(result <- ui_g_km( id = "testid", - data = data, adtte_name = "ADTTE", mae_name = mae_name, summary_funs = list( diff --git a/tests/testthat/test-pca.R b/tests/testthat/test-pca.R index df2b3af2..d33e334c 100644 --- a/tests/testthat/test-pca.R +++ b/tests/testthat/test-pca.R @@ -2,10 +2,9 @@ test_that("ui_g_pca creates HTML", { mae_name <- "MyMAE" - data <- list(MyMAE = function() hermes::multi_assay_experiment) + data <- teal.data::teal_data(MyMAE = function() hermes::multi_assay_experiment) result <- ui_g_pca( id = "testid", - data = data, mae_name = mae_name, pre_output = NULL, post_output = NULL diff --git a/tests/testthat/test-quality.R b/tests/testthat/test-quality.R index a22b0d5d..6744ad82 100644 --- a/tests/testthat/test-quality.R +++ b/tests/testthat/test-quality.R @@ -3,10 +3,9 @@ test_that("ui_g_quality creates expected HTML", { mae_name <- "MyMAE" set.seed(123) - data <- list(MyMAE = function() hermes::multi_assay_experiment) + data <- teal.data::teal_data(MyMAE = function() hermes::multi_assay_experiment) expect_silent(result <- ui_g_quality( id = "testid", - data = data, mae_name = mae_name, pre_output = NULL, post_output = NULL diff --git a/tests/testthat/test-scatterplot.R b/tests/testthat/test-scatterplot.R index 90ee9ca2..5c7de54b 100644 --- a/tests/testthat/test-scatterplot.R +++ b/tests/testthat/test-scatterplot.R @@ -3,10 +3,9 @@ test_that("ui_g_scatterplot creates expected HTML", { mae_name <- "MyMAE" set.seed(123) - data <- list(MyMAE = function() hermes::multi_assay_experiment) + data <- teal.data::teal_data(MyMAE = function() hermes::multi_assay_experiment) expect_silent(result <- ui_g_scatterplot( id = "testid", - data = data, mae_name = mae_name, summary_funs = list( Mean = colMeans diff --git a/tests/testthat/test-volcanoplot.R b/tests/testthat/test-volcanoplot.R index 25800a80..eccbe30c 100644 --- a/tests/testthat/test-volcanoplot.R +++ b/tests/testthat/test-volcanoplot.R @@ -5,7 +5,6 @@ test_that("ui_g_volcanoplot creates expected HTML", { data <- list(MyMAE = function() hermes::multi_assay_experiment) expect_silent(result <- ui_g_volcanoplot( id = "testid", - data = data, mae_name = mae_name, pre_output = NULL, post_output = NULL diff --git a/vignettes/Getting_Started.Rmd b/vignettes/Getting_Started.Rmd index 4cbb0adb..2cd05961 100644 --- a/vignettes/Getting_Started.Rmd +++ b/vignettes/Getting_Started.Rmd @@ -37,16 +37,11 @@ In `teal.modules.hermes` we provide modules that make the experiment and assay selection super easy, see here for the UI part: ```{r} -ui <- function(id, - data, - mae_name) { +ui <- function(id, mae_name) { ns <- NS(id) teal.widgets::standard_layout( - encoding = div( - experimentSpecInput(ns("experiment"), data, mae_name), - assaySpecInput(ns("assay")) - ), + encoding = uiOutput(ns("encoding_ui")), output = plotOutput(ns("awesome_plot")) ) } @@ -63,6 +58,12 @@ srv <- function(input, data, filter_panel_api, mae_name) { + output$encoding_ui <- renderUI({ + div( + experimentSpecInput(session$ns("experiment"), data, mae_name), + assaySpecInput(session$ns("assay")) + ) + }) experiment <- experimentSpecServer( "experiment", data = data, @@ -94,9 +95,7 @@ Now let's assume you want to spin up your app for an MAE. ```{r} awesome_app <- function(mae, label = "My awesome app") { mae_name <- "MAE" - mae <- hermes::lapply(mae, hermes::HermesData) - mae_data <- dataset(mae_name, mae) - data <- teal_data(mae_data) + data <- teal_data(MAE = hermes::lapply(mae, hermes::HermesData)) app <- init( data = data, modules = teal::modules(