Skip to content

Commit a0df4b5

Browse files
committed
add option to remove empty columns
1 parent 72afb30 commit a0df4b5

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

R/tm_t_crosstable.R

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
#'
2626
#' @inherit shared_params return
2727
#'
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+
#'
2836
#' @section Decorating Module:
2937
#'
3038
#' 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
245253
bslib::accordion_panel(
246254
title = "Table settings",
247255
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)
249258
)
250259
),
251260
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,
352361

353362
show_percentage <- input$show_percentage
354363
show_total <- input$show_total
364+
remove_zero_columns <- input$remove_zero_columns
355365

356366
plot_title <- paste(
357367
"Cross-Table of",
@@ -416,9 +426,12 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y,
416426
substitute(
417427
expr = {
418428
ANL <- tern::df_explicit_na(ANL)
429+
if (remove_zero_columns) {
430+
ANL[[y_name]] <- droplevels(ANL[[y_name]])
431+
}
419432
table <- rtables::build_table(lyt = table, df = ANL[order(ANL[[y_name]]), ])
420433
},
421-
env = list(y_name = y_name)
434+
env = list(y_name = y_name, remove_zero_columns = remove_zero_columns)
422435
)
423436
)
424437
})

man/tm_t_crosstable.Rd

Lines changed: 14 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)