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")`.
@@ -163,6 +166,7 @@ tm_t_crosstable <- function(label = "Cross Table",
163166 y ,
164167 show_percentage = TRUE ,
165168 show_total = TRUE ,
169+ remove_zero_columns = FALSE ,
166170 pre_output = NULL ,
167171 post_output = NULL ,
168172 basic_table_args = teal.widgets :: basic_table_args(),
@@ -183,6 +187,7 @@ tm_t_crosstable <- function(label = "Cross Table",
183187
184188 checkmate :: assert_flag(show_percentage )
185189 checkmate :: assert_flag(show_total )
190+ checkmate :: assert_flag(remove_zero_columns )
186191 checkmate :: assert_multi_class(pre_output , c(" shiny.tag" , " shiny.tag.list" , " html" ), null.ok = TRUE )
187192 checkmate :: assert_multi_class(post_output , c(" shiny.tag" , " shiny.tag.list" , " html" ), null.ok = TRUE )
188193 checkmate :: assert_class(basic_table_args , classes = " basic_table_args" )
@@ -197,6 +202,7 @@ tm_t_crosstable <- function(label = "Cross Table",
197202 label = label ,
198203 x = x ,
199204 y = y ,
205+ remove_zero_columns = remove_zero_columns ,
200206 basic_table_args = basic_table_args ,
201207 decorators = decorators
202208 )
@@ -215,7 +221,7 @@ tm_t_crosstable <- function(label = "Cross Table",
215221}
216222
217223# UI function for the cross-table module
218- ui_t_crosstable <- function (id , x , y , show_percentage , show_total , pre_output , post_output , ... ) {
224+ ui_t_crosstable <- function (id , x , y , show_percentage , show_total , remove_zero_columns , pre_output , post_output , ... ) {
219225 args <- list (... )
220226 ns <- NS(id )
221227 is_single_dataset <- teal.transform :: is_single_dataset(x , y )
@@ -254,7 +260,7 @@ ui_t_crosstable <- function(id, x, y, show_percentage, show_total, pre_output, p
254260 title = " Table settings" ,
255261 checkboxInput(ns(" show_percentage" ), " Show column percentage" , value = show_percentage ),
256262 checkboxInput(ns(" show_total" ), " Show total column" , value = show_total ),
257- checkboxInput(ns(" remove_zero_columns" ), " Remove zero-only columns" , value = FALSE )
263+ checkboxInput(ns(" remove_zero_columns" ), " Remove zero-only columns" , value = remove_zero_columns )
258264 )
259265 ),
260266 ui_decorate_teal_data(ns(" decorator" ), decorators = select_decorators(args $ decorators , " table" ))
@@ -268,7 +274,7 @@ ui_t_crosstable <- function(id, x, y, show_percentage, show_total, pre_output, p
268274}
269275
270276# Server function for the cross-table module
271- srv_t_crosstable <- function (id , data , reporter , filter_panel_api , label , x , y , basic_table_args , decorators ) {
277+ srv_t_crosstable <- function (id , data , reporter , filter_panel_api , label , x , y , remove_zero_columns , basic_table_args , decorators ) {
272278 with_reporter <- ! missing(reporter ) && inherits(reporter , " Reporter" )
273279 with_filter <- ! missing(filter_panel_api ) && inherits(filter_panel_api , " FilterPanelAPI" )
274280 checkmate :: assert_class(data , " reactive" )
0 commit comments