From aa11b00fb7ad0457ceca23a624c19a15a4b1bb84 Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 19 Jun 2024 16:54:57 -0400 Subject: [PATCH 1/3] Add `ihtml.height` for interactive. --- NEWS.md | 2 ++ R/dt_options.R | 1 + R/opts.R | 11 +++++++++-- R/render_as_i_html.R | 3 ++- R/tab_create_modify.R | 5 +++++ man/opt_interactive.Rd | 6 +++++- man/tab_options.Rd | 5 +++++ 7 files changed, 29 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 78daeb1578..bc000231d2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # gt (development version) +* `opt_interactive()` gains `height` to help specify your widget's height (@olivroy, #1544). + * `opt_interactive()` now shows row names if `rownames_to_stub = TRUE` (@olivroy, #1702). * `data_color()` throws a more informative error message if `rows` didn't resolve to anything (@olivroy, #1659). diff --git a/R/dt_options.R b/R/dt_options.R index d6f9c473ba..138a4150a5 100644 --- a/R/dt_options.R +++ b/R/dt_options.R @@ -224,6 +224,7 @@ dt_options_tbl <- "container_overflow_x", FALSE, "container", "overflow","auto", "container_overflow_y", FALSE, "container", "overflow","auto", "ihtml_active", FALSE, "interactive", "logical", FALSE, + "ihtml_height", FALSE, "interactive", "px", "auto", "ihtml_use_pagination", FALSE, "interactive", "logical", TRUE, "ihtml_use_pagination_info", FALSE, "interactive", "logical", TRUE, "ihtml_use_sorting", FALSE, "interactive", "logical", TRUE, diff --git a/R/opts.R b/R/opts.R index 73a73110e9..b3c54feb1d 100644 --- a/R/opts.R +++ b/R/opts.R @@ -220,6 +220,7 @@ get_colorized_params <- function( #' - `ihtml.page_size_default` #' - `ihtml.page_size_values` #' - `ihtml.pagination_type` +#' - `ihtml.height` #' #' @inheritParams fmt_number #' @@ -333,6 +334,10 @@ get_colorized_params <- function( #' with a stepper for the page number. With `"simple"`, only the 'previous' #' and 'next' buttons are displayed. #' +#' @param ihtml.height *Height of interactive HTML table* +#' +#' Height of the table in pixels. Defaults to `"auto"` for automatic sizing. +#' #' @return An object of class `gt_tbl`. #' #' @section Examples: @@ -413,7 +418,8 @@ opt_interactive <- function( use_page_size_select = FALSE, page_size_default = 10, page_size_values = c(10, 25, 50, 100), - pagination_type = c("numbers", "jump", "simple") + pagination_type = c("numbers", "jump", "simple"), + height = "auto" ) { # Perform input object validation @@ -436,7 +442,8 @@ opt_interactive <- function( ihtml.use_page_size_select = use_page_size_select, ihtml.page_size_default = page_size_default, ihtml.page_size_values = page_size_values, - ihtml.pagination_type = pagination_type + ihtml.pagination_type = pagination_type, + ihtml.height = height ) } diff --git a/R/render_as_i_html.R b/R/render_as_i_html.R index f4ae548a43..5a879011c1 100644 --- a/R/render_as_i_html.R +++ b/R/render_as_i_html.R @@ -166,6 +166,7 @@ render_as_ihtml <- function(data, id) { # Get options settable in `tab_options()` opt_val <- dt_options_get_value + height <- opt_val(data = data, option = "ihtml_height") use_pagination <- opt_val(data = data, option = "ihtml_use_pagination") use_pagination_info <- opt_val(data = data, option = "ihtml_use_pagination_info") use_search <- opt_val(data = data, option = "ihtml_use_search") @@ -505,7 +506,7 @@ render_as_ihtml <- function(data, id) { rowStyle = NULL, fullWidth = TRUE, width = table_width, - height = "auto", + height = height, theme = tbl_theme, language = lang_defs, elementId = id, diff --git a/R/tab_create_modify.R b/R/tab_create_modify.R index 783ae77b9b..85d886c3cd 100644 --- a/R/tab_create_modify.R +++ b/R/tab_create_modify.R @@ -4347,6 +4347,10 @@ set_style.cells_source_notes <- function(loc, data, style) { #' page number. With `"simple"`, only the 'previous' and 'next' buttons are #' displayed. #' +#' @param ihtml.height *Height of interactive HTML table* +#' +#' Height of the table in pixels. Defaults to `"auto"` for automatic sizing. +#' #' @param page.orientation *Set RTF page orientation* #' #' For RTF output, this provides an two options for page @@ -4711,6 +4715,7 @@ tab_options <- function( ihtml.page_size_default = NULL, ihtml.page_size_values = NULL, ihtml.pagination_type = NULL, + ihtml.height = NULL, page.orientation = NULL, page.numbering = NULL, page.header.use_tbl_headings = NULL, diff --git a/man/opt_interactive.Rd b/man/opt_interactive.Rd index 21bd46efd8..3c23c1b390 100644 --- a/man/opt_interactive.Rd +++ b/man/opt_interactive.Rd @@ -19,7 +19,8 @@ opt_interactive( use_page_size_select = FALSE, page_size_default = 10, page_size_values = c(10, 25, 50, 100), - pagination_type = c("numbers", "jump", "simple") + pagination_type = c("numbers", "jump", "simple"), + height = "auto" ) } \arguments{ @@ -139,6 +140,8 @@ one of three options for the layout of pagination controls. The default is 'previous' and 'next' buttons. The \code{"jump"} option provides an input field with a stepper for the page number. With \code{"simple"}, only the 'previous' and 'next' buttons are displayed.} + +\item{height}{Height of the table in pixels. Defaults to \code{"auto"} for automatic sizing.} } \value{ An object of class \code{gt_tbl}. @@ -166,6 +169,7 @@ This function serves as a shortcut for setting the following options in \item \code{ihtml.page_size_default} \item \code{ihtml.page_size_values} \item \code{ihtml.pagination_type} +\item \code{ihtml.height} } } \section{Examples}{ diff --git a/man/tab_options.Rd b/man/tab_options.Rd index 2e417af3b6..66047ab6a8 100644 --- a/man/tab_options.Rd +++ b/man/tab_options.Rd @@ -177,6 +177,7 @@ tab_options( ihtml.page_size_default = NULL, ihtml.page_size_values = NULL, ihtml.pagination_type = NULL, + ihtml.height = NULL, page.orientation = NULL, page.numbering = NULL, page.header.use_tbl_headings = NULL, @@ -588,6 +589,10 @@ buttons. The \code{"jump"} option provides an input field with a stepper for the page number. With \code{"simple"}, only the 'previous' and 'next' buttons are displayed.} +\item{ihtml.height}{\emph{Height of interactive HTML table} + +Height of the table in pixels. Defaults to \code{"auto"} for automatic sizing.} + \item{page.orientation}{\emph{Set RTF page orientation} For RTF output, this provides an two options for page From 1668cd130c512618b04bbf3e4820080296b95041 Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 19 Jun 2024 16:59:22 -0400 Subject: [PATCH 2/3] Correct name --- R/opts.R | 2 +- man/opt_interactive.Rd | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/R/opts.R b/R/opts.R index b3c54feb1d..622dd9115f 100644 --- a/R/opts.R +++ b/R/opts.R @@ -334,7 +334,7 @@ get_colorized_params <- function( #' with a stepper for the page number. With `"simple"`, only the 'previous' #' and 'next' buttons are displayed. #' -#' @param ihtml.height *Height of interactive HTML table* +#' @param height *Height of interactive HTML table* #' #' Height of the table in pixels. Defaults to `"auto"` for automatic sizing. #' diff --git a/man/opt_interactive.Rd b/man/opt_interactive.Rd index 3c23c1b390..dfbe1c0cd4 100644 --- a/man/opt_interactive.Rd +++ b/man/opt_interactive.Rd @@ -141,7 +141,9 @@ one of three options for the layout of pagination controls. The default is with a stepper for the page number. With \code{"simple"}, only the 'previous' and 'next' buttons are displayed.} -\item{height}{Height of the table in pixels. Defaults to \code{"auto"} for automatic sizing.} +\item{height}{\emph{Height of interactive HTML table} + +Height of the table in pixels. Defaults to \code{"auto"} for automatic sizing.} } \value{ An object of class \code{gt_tbl}. From 581983b2a24da7a577fba0d7ace9b0d6aa8dc912 Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 19 Jun 2024 17:27:52 -0400 Subject: [PATCH 3/3] Update test to reflect the extra option! --- tests/testthat/helper-gt_attr_expectations.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/helper-gt_attr_expectations.R b/tests/testthat/helper-gt_attr_expectations.R index 8e58ac824b..7988803298 100644 --- a/tests/testthat/helper-gt_attr_expectations.R +++ b/tests/testthat/helper-gt_attr_expectations.R @@ -102,7 +102,7 @@ expect_tab <- function(tab, df) { dt_options_get(data = tab) %>% dim() %>% - expect_equal(c(190, 5)) + expect_equal(c(191, 5)) dt_transforms_get(data = tab) %>% expect_length(0)