Skip to content

Commit 45b9080

Browse files
authored
Merge branch 'main' into teal_reportable
Signed-off-by: Marcin <[email protected]>
2 parents 3f82dca + c6c008d commit 45b9080

File tree

5 files changed

+66
-14
lines changed

5 files changed

+66
-14
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ default_language_version:
66
python: python3
77
repos:
88
- repo: https://github.com/lorenzwalthert/precommit
9-
rev: v0.4.3.9011
9+
rev: v0.4.3.9012
1010
hooks:
1111
- id: style-files
1212
name: Style code with `styler`

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Type: Package
22
Package: teal.modules.general
33
Title: General Modules for 'teal' Applications
4-
Version: 0.4.1.9005
5-
Date: 2025-06-23
4+
Version: 0.4.1.9006
5+
Date: 2025-07-08
66
Authors@R: c(
77
person("Dawid", "Kaledkowski", , "[email protected]", role = c("aut", "cre")),
88
person("Pawel", "Rucki", , "[email protected]", role = "aut"),

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
# teal.modules.general 0.4.1.9005
1+
# teal.modules.general 0.4.1.9006
22

33
# teal.modules.general 0.4.1
44

55
### Bug fixes
66
* Fixes output is not updated when filter is added for the modules: `tm_a_pca`, `tm_a_regression`, `tm_g_scatterplot`, `tm_g_association`, `tm_g_bivariate`, `tm_g_distribution`, `tm_g_response`, `tm_t_crosstable` (#870)
77

8+
### Enhancements
9+
* Added `remove_zero_columns` to `tm_t_crosstable` to add an option to remove empty columns (#890)
10+
811
# teal.modules.general 0.4.0
912

1013
### Enhancements

R/tm_t_crosstable.R

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,23 @@
1919
#' @param show_total (`logical(1)`)
2020
#' Indicates whether to show total column.
2121
#' Defaults to `TRUE`.
22+
#' @param remove_zero_columns (`logical(1)`)
23+
#' Indicates whether to remove columns that contain only zeros from the output table.
24+
#' Defaults to `FALSE`.
2225
#'
2326
#' @note For more examples, please see the vignette "Using cross table" via
2427
#' `vignette("using-cross-table", package = "teal.modules.general")`.
2528
#'
2629
#' @inherit shared_params return
2730
#'
31+
#' @section Table Settings:
32+
#' The module provides several table settings that can be adjusted:
33+
#' \itemize{
34+
#' \item \code{Show column percentage}: Shows column percentages when enabled
35+
#' \item \code{Show total column}: Shows a total column when enabled
36+
#' \item \code{Remove zero-only columns}: Removes columns that contain only zeros from the output table
37+
#' }
38+
#'
2839
#' @section Decorating Module:
2940
#'
3041
#' This module generates the following objects, which can be modified in place using decorators:
@@ -157,6 +168,7 @@ tm_t_crosstable <- function(label = "Cross Table",
157168
y,
158169
show_percentage = TRUE,
159170
show_total = TRUE,
171+
remove_zero_columns = FALSE,
160172
pre_output = NULL,
161173
post_output = NULL,
162174
basic_table_args = teal.widgets::basic_table_args(),
@@ -177,6 +189,7 @@ tm_t_crosstable <- function(label = "Cross Table",
177189

178190
checkmate::assert_flag(show_percentage)
179191
checkmate::assert_flag(show_total)
192+
checkmate::assert_flag(remove_zero_columns)
180193
checkmate::assert_multi_class(pre_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
181194
checkmate::assert_multi_class(post_output, c("shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE)
182195
checkmate::assert_class(basic_table_args, classes = "basic_table_args")
@@ -191,6 +204,7 @@ tm_t_crosstable <- function(label = "Cross Table",
191204
label = label,
192205
x = x,
193206
y = y,
207+
remove_zero_columns = remove_zero_columns,
194208
basic_table_args = basic_table_args,
195209
decorators = decorators
196210
)
@@ -209,7 +223,7 @@ tm_t_crosstable <- function(label = "Cross Table",
209223
}
210224

211225
# UI function for the cross-table module
212-
ui_t_crosstable <- function(id, x, y, show_percentage, show_total, pre_output, post_output, ...) {
226+
ui_t_crosstable <- function(id, x, y, show_percentage, show_total, remove_zero_columns, pre_output, post_output, ...) {
213227
args <- list(...)
214228
ns <- NS(id)
215229
is_single_dataset <- teal.transform::is_single_dataset(x, y)
@@ -244,7 +258,8 @@ ui_t_crosstable <- function(id, x, y, show_percentage, show_total, pre_output, p
244258
bslib::accordion_panel(
245259
title = "Table settings",
246260
checkboxInput(ns("show_percentage"), "Show column percentage", value = show_percentage),
247-
checkboxInput(ns("show_total"), "Show total column", value = show_total)
261+
checkboxInput(ns("show_total"), "Show total column", value = show_total),
262+
checkboxInput(ns("remove_zero_columns"), "Remove zero-only columns", value = remove_zero_columns)
248263
)
249264
),
250265
ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(args$decorators, "table"))
@@ -258,7 +273,7 @@ ui_t_crosstable <- function(id, x, y, show_percentage, show_total, pre_output, p
258273
}
259274

260275
# Server function for the cross-table module
261-
srv_t_crosstable <- function(id, data, label, x, y, basic_table_args, decorators) {
276+
srv_t_crosstable <- function(id, data, label, x, y, remove_zero_columns, basic_table_args, decorators) {
262277
checkmate::assert_class(data, "reactive")
263278
checkmate::assert_class(isolate(data()), "teal_data")
264279
moduleServer(id, function(input, output, session) {
@@ -352,6 +367,7 @@ srv_t_crosstable <- function(id, data, label, x, y, basic_table_args, decorators
352367

353368
show_percentage <- input$show_percentage
354369
show_total <- input$show_total
370+
remove_zero_columns <- input$remove_zero_columns
355371

356372
plot_title <- paste(
357373
"Cross-Table of",
@@ -415,14 +431,32 @@ srv_t_crosstable <- function(id, data, label, x, y, basic_table_args, decorators
415431
)
416432
) %>%
417433
teal.code::eval_code(
418-
substitute(
419-
expr = {
420-
ANL <- tern::df_explicit_na(ANL)
421-
table <- rtables::build_table(lyt = table, df = ANL[order(ANL[[y_name]]), ])
422-
},
423-
env = list(y_name = y_name)
424-
)
434+
expression(ANL <- tern::df_explicit_na(ANL))
425435
)
436+
437+
if (remove_zero_columns) {
438+
obj <- obj %>%
439+
teal.code::eval_code(
440+
substitute(
441+
expr = {
442+
ANL[[y_name]] <- droplevels(ANL[[y_name]])
443+
table <- rtables::build_table(lyt = table, df = ANL[order(ANL[[y_name]]), ])
444+
},
445+
env = list(y_name = y_name)
446+
)
447+
)
448+
} else {
449+
obj <- obj %>%
450+
teal.code::eval_code(
451+
substitute(
452+
expr = {
453+
table <- rtables::build_table(lyt = table, df = ANL[order(ANL[[y_name]]), ])
454+
},
455+
env = list(y_name = y_name)
456+
)
457+
)
458+
}
459+
obj
426460
})
427461

428462
decorated_output_q <- srv_decorate_teal_data(

man/tm_t_crosstable.Rd

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

0 commit comments

Comments
 (0)