Skip to content

Commit

Permalink
Using teal_data in the modules instead of tdata (#344)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Aleksander Chlebowski <[email protected]>
Co-authored-by: unknown <[email protected]>
  • Loading branch information
4 people authored Dec 8, 2023
1 parent a29dd97 commit 6fb3af1
Show file tree
Hide file tree
Showing 42 changed files with 223 additions and 185 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Depends:
ggplot2,
R (>= 3.6),
shiny,
teal (>= 0.14.0.9019)
teal (>= 0.14.0.9027)
Imports:
checkmate,
DT,
Expand All @@ -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),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(<teal_data>)` in the server

### Enhancements

Expand Down
27 changes: 17 additions & 10 deletions R/adtteSpec.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions R/argument_convention.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(<teal_data>)` 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
Expand Down
24 changes: 11 additions & 13 deletions R/assaySpec.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions R/barplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions R/boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions R/experimentSpec.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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),
Expand Down
9 changes: 6 additions & 3 deletions R/forestplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)),
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions R/geneSpec.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions R/km.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,20 @@ 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
teal.reporter::simple_reporter_ui(ns("simple_reporter")),
###
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)),
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions R/pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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'",
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions R/quality.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 6fb3af1

Please sign in to comment.