diff --git a/R/tm_outliers.R b/R/tm_outliers.R index 12e212e2e..a7760eeec 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -42,17 +42,21 @@ #' ) #' ) #' ), -#' categorical_var = data_extract_spec( -#' dataname = "ADSL", -#' filter = filter_spec( -#' vars = vars, -#' choices = value_choices(ADSL, vars$selected), -#' selected = value_choices(ADSL, vars$selected), -#' multiple = TRUE +#' categorical_var = list( +#' data_extract_spec( +#' dataname = "ADSL", +#' filter = filter_spec( +#' vars = vars, +#' choices = value_choices(ADSL, vars$selected), +#' selected = value_choices(ADSL, vars$selected), +#' multiple = TRUE +#' ) #' ) #' ), -#' ggplot2_args = teal.widgets::ggplot2_args( -#' labs = list(subtitle = "Plot generated by Outliers Module") +#' ggplot2_args = list( +#' teal.widgets::ggplot2_args( +#' labs = list(subtitle = "Plot generated by Outliers Module") +#' ) #' ) #' ) #' ) @@ -125,13 +129,16 @@ ui_outliers <- function(id, ...) { id = ns("tabs"), tabPanel( "Boxplot", - teal.widgets::plot_with_settings_ui(id = ns("box_plot"))), + teal.widgets::plot_with_settings_ui(id = ns("box_plot")) + ), tabPanel( "Density Plot", - teal.widgets::plot_with_settings_ui(id = ns("density_plot"))), + teal.widgets::plot_with_settings_ui(id = ns("density_plot")) + ), tabPanel( "Cumulative Distribution Plot", - teal.widgets::plot_with_settings_ui(id = ns("cum_density_plot"))) + teal.widgets::plot_with_settings_ui(id = ns("cum_density_plot")) + ) ), br(), hr(), uiOutput(ns("table_ui_wrap")) @@ -248,10 +255,11 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, rule_diff <- function(other) { function(value) { - othervalue <- selector_list()[[other]]()[["select"]] + othervalue <- tryCatch(selector_list()[["categorical_var"]]()[["select"]], error = function(e) NULL) if (!is.null(othervalue)) { - if (identical(othervalue, value)) + if (identical(othervalue, value)) { "`Variable` and `Categorical factor` cannot be the same" + } } } } @@ -409,7 +417,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, q1_q3 <- stats::quantile(outlier_var_name, probs = c(0.25, 0.75)) iqr <- q1_q3[2] - q1_q3[1] !(outlier_var_name >= q1_q3[1] - outlier_definition_param * iqr & - outlier_var_name <= q1_q3[2] + outlier_definition_param * iqr) + outlier_var_name <= q1_q3[2] + outlier_definition_param * iqr) }), env = list( outlier_var_name = as.name(outlier_var), @@ -558,16 +566,16 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, expr = { if (iv_r()$is_valid()) { categorical_var <- as.vector(merged$anl_input_r()$columns_source$categorical_var) - DT::datatable( - common_code_q()[["summary_table"]], - options = list( - dom = "t", - autoWidth = TRUE, - columnDefs = list(list(width = "200px", targets = "_all")) + if (!is.null(categorical_var)) { + DT::datatable( + common_code_q()[["summary_table"]], + options = list( + dom = "t", + autoWidth = TRUE, + columnDefs = list(list(width = "200px", targets = "_all")) + ) ) - ) - } else { - NULL + } } } ) diff --git a/man/tm_outliers.Rd b/man/tm_outliers.Rd index 356f23961..e2b0931bf 100644 --- a/man/tm_outliers.Rd +++ b/man/tm_outliers.Rd @@ -80,17 +80,21 @@ app <- init( ) ) ), - categorical_var = data_extract_spec( - dataname = "ADSL", - filter = filter_spec( - vars = vars, - choices = value_choices(ADSL, vars$selected), - selected = value_choices(ADSL, vars$selected), - multiple = TRUE + categorical_var = list( + data_extract_spec( + dataname = "ADSL", + filter = filter_spec( + vars = vars, + choices = value_choices(ADSL, vars$selected), + selected = value_choices(ADSL, vars$selected), + multiple = TRUE + ) ) ), - ggplot2_args = teal.widgets::ggplot2_args( - labs = list(subtitle = "Plot generated by Outliers Module") + ggplot2_args = list( + teal.widgets::ggplot2_args( + labs = list(subtitle = "Plot generated by Outliers Module") + ) ) ) )