From 2dde21d5c21596c7725b2fe525d61a80667f325c Mon Sep 17 00:00:00 2001 From: kartikeya kirar Date: Thu, 23 Nov 2023 14:46:15 +0530 Subject: [PATCH] `tdata` to `teal_data` - `tm_outliers` (#612) Example App ``` data <- teal_data() data <- within(data, { ADSL <- teal.modules.general::rADSL }) datanames <- c("ADSL") datanames(data) <- datanames join_keys(data) <- default_cdisc_join_keys[datanames] fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor))) vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl)) app <- teal::init( data = data, modules = teal::modules( teal.modules.general::tm_outliers( outlier_var = list( teal.transform::data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), selected = "AGE", multiple = FALSE, fixed = FALSE ) ) ), categorical_var = list( teal.transform::data_extract_spec( dataname = "ADSL", filter = teal.transform::filter_spec( vars = vars, choices = value_choices(data[["ADSL"]], vars$selected), selected = value_choices(data[["ADSL"]], vars$selected), multiple = TRUE ) ) ), ggplot2_args = list( teal.widgets::ggplot2_args( labs = list(subtitle = "Plot generated by Outliers Module") ) ) ) ) ) shinyApp(app$ui, app$server) ``` --- R/tm_outliers.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/tm_outliers.R b/R/tm_outliers.R index 937d7338d..9da177da2 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -250,7 +250,8 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, categorical_var, plot_height, plot_width, ggplot2_args) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") - checkmate::assert_class(data, "tdata") + checkmate::assert_class(data, "reactive") + checkmate::assert_class(isolate(data()), "teal_data") moduleServer(id, function(input, output, session) { vars <- list(outlier_var = outlier_var, categorical_var = categorical_var) @@ -293,13 +294,12 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, anl_merged_input <- teal.transform::merge_expression_srv( selector_list = reactive_select_input, datasets = data, - join_keys = teal.data::join_keys(data), merge_function = "dplyr::inner_join" ) anl_merged_q <- reactive({ req(anl_merged_input()) - teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)) %>% + data() %>% teal.code::eval_code(as.expression(anl_merged_input()$expr)) }) @@ -316,7 +316,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, }) # Used to create outlier table and the dropdown with additional columns - dataname_first <- names(data)[[1]] + dataname_first <- isolate(teal.data::datanames(data())[[1]]) common_code_q <- reactive({ shiny::req(iv_r()$is_valid()) @@ -476,7 +476,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, }, env = list( dataname = as.name(dataname_first), - join_keys = as.character(teal.data::join_keys(data)[dataname_first, dataname_first]) + join_keys = as.character(teal.data::join_keys(data())[dataname_first, dataname_first]) ) ) ) @@ -976,7 +976,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, brushing = TRUE ) - choices <- teal.transform::variable_choices(data[[dataname_first]]()) + choices <- teal.transform::variable_choices(data()[[dataname_first]]) observeEvent(common_code_q(), { ANL_OUTLIER <- common_code_q()[["ANL_OUTLIER"]] # nolint