|
25 | 25 | #' |
26 | 26 | #' @inherit shared_params return |
27 | 27 | #' |
| 28 | +#' @section Table Settings: |
| 29 | +#' The module provides several table settings that can be adjusted: |
| 30 | +#' \itemize{ |
| 31 | +#' \item \code{Show column percentage}: Shows column percentages when enabled |
| 32 | +#' \item \code{Show total column}: Shows a total column when enabled |
| 33 | +#' \item \code{Remove zero-only columns}: Removes columns that contain only zeros from the output table |
| 34 | +#' } |
| 35 | +#' |
28 | 36 | #' @section Decorating Module: |
29 | 37 | #' |
30 | 38 | #' This module generates the following objects, which can be modified in place using decorators: |
@@ -245,7 +253,8 @@ ui_t_crosstable <- function(id, x, y, show_percentage, show_total, pre_output, p |
245 | 253 | bslib::accordion_panel( |
246 | 254 | title = "Table settings", |
247 | 255 | checkboxInput(ns("show_percentage"), "Show column percentage", value = show_percentage), |
248 | | - checkboxInput(ns("show_total"), "Show total column", value = show_total) |
| 256 | + checkboxInput(ns("show_total"), "Show total column", value = show_total), |
| 257 | + checkboxInput(ns("remove_zero_columns"), "Remove zero-only columns", value = FALSE) |
249 | 258 | ) |
250 | 259 | ), |
251 | 260 | ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(args$decorators, "table")) |
@@ -352,6 +361,7 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y, |
352 | 361 |
|
353 | 362 | show_percentage <- input$show_percentage |
354 | 363 | show_total <- input$show_total |
| 364 | + remove_zero_columns <- input$remove_zero_columns |
355 | 365 |
|
356 | 366 | plot_title <- paste( |
357 | 367 | "Cross-Table of", |
@@ -416,9 +426,12 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y, |
416 | 426 | substitute( |
417 | 427 | expr = { |
418 | 428 | ANL <- tern::df_explicit_na(ANL) |
| 429 | + if (remove_zero_columns) { |
| 430 | + ANL[[y_name]] <- droplevels(ANL[[y_name]]) |
| 431 | + } |
419 | 432 | table <- rtables::build_table(lyt = table, df = ANL[order(ANL[[y_name]]), ]) |
420 | 433 | }, |
421 | | - env = list(y_name = y_name) |
| 434 | + env = list(y_name = y_name, remove_zero_columns = remove_zero_columns) |
422 | 435 | ) |
423 | 436 | ) |
424 | 437 | }) |
|
0 commit comments