From 3fff383af743d910c3535a2b704c953c5e5fc943 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Thu, 5 Nov 2026 13:14:14 -0500 Subject: [PATCH 1/3] Fix column order and show/hide menu with SOC excluded; deprecate display_diff_toggle - `display_soc_toggle = FALSE` dropped `soc_name` before `lt_move()` ran, so the figure columns lost their anchor and stayed after n/(%). The SOC column is now left out of the table data and the figures anchor on `name`. - Always show the "Show/Hide columns" menu, and no longer add a `soc_name` filter chip when SOC is excluded. - Deprecate `display_diff_toggle`: the risk-difference columns are always offered in the menu (hidden by default unless "diff" is in `display`). Co-Authored-By: Claude Code --- NEWS.md | 1 + R/ae_forestly.R | 27 +++++++++--- R/lt_table.R | 61 ++++++++++++-------------- man/ae_forestly.Rd | 12 +++-- tests/testthat/test-ae_forestly.R | 9 ++-- tests/testthat/test-lt_table.R | 21 +++++---- vignettes/customize-toggle-buttons.Rmd | 7 ++- 7 files changed, 76 insertions(+), 62 deletions(-) diff --git a/NEWS.md b/NEWS.md index f6f2592..2b984ca 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ - Reveal a truncated table cell's full text on hover; figure cells, the drill-down detail, and the control-bar and per-column filter rows (whose chips, funnels, and popovers must stay visible) are exempt. - Speed up `format_ae_listing()` by vectorizing the per-row loops that map `AEACN`, `AEOUT`, and missing `ADURN` durations to display labels, avoiding quadratic-time column copies on large AE listings. - Rename the misspelled `ae_forestly()` argument `dowload_button` to `download_button` (#173). +- Deprecate the `display_diff_toggle` argument of `ae_forestly()`: the numeric risk-difference columns are always offered in the "Show/Hide columns" menu. With `display_soc_toggle = FALSE`, the SOC column is now left out of the table entirely, and the "Show/Hide columns" menu is always shown. - Add a treatment-group picker to the drill-down: a checklist in the table's control bar chooses which arm(s) appear in each expanded AE listing, filtering the detail client-side (built on `lt`'s `LT.ui` popover/checklist widgets and `el._lt.resetDetail`). # forestly 0.1.6 diff --git a/R/ae_forestly.R b/R/ae_forestly.R index c539200..b9603b9 100644 --- a/R/ae_forestly.R +++ b/R/ae_forestly.R @@ -19,8 +19,14 @@ #' Display interactive forest plot #' #' @param outdata An `outdata` object created by [format_ae_forestly()]. -#' @param display_soc_toggle A boolean value to display SOC toggle button. -#' @param display_diff_toggle A boolean value to display risk difference toggle button. +#' @param display_soc_toggle Whether to include the SOC column in the table. If +#' `TRUE`, it is offered in the "Show/Hide columns" menu (hidden by default); if +#' `FALSE`, it is left out of the table entirely. Including it makes the saved +#' HTML file slightly larger, which only matters for very large data sets. +#' @param display_diff_toggle Deprecated and ignored. The numeric risk-difference +#' columns are always in the table and, unless `"diff"` is in the `display` +#' argument of [format_ae_forestly()], offered in the "Show/Hide columns" menu +#' (hidden by default). #' @param filter The variable the incidence slider (the "Incidence (%) in One or #' More Treatment Groups" chip in the control bar) filters on: `"prop"` for #' incidence (%) or `"n"` for the number of AEs. Use `NULL` to hide the slider. @@ -151,7 +157,7 @@ #' } ae_forestly <- function(outdata, display_soc_toggle = TRUE, - display_diff_toggle = FALSE, + display_diff_toggle = NULL, filter = c("prop", "n"), filter_label = NULL, filter_range = NULL, @@ -159,6 +165,14 @@ ae_forestly <- function(outdata, max_page = NULL, download_button = FALSE, width = NULL) { + if (!is.null(display_diff_toggle)) { + warning( + "`display_diff_toggle` is deprecated and ignored; the risk-difference ", + "columns are always offered in the Show/Hide columns menu.", + call. = FALSE + ) + } + # Set filter parameter if (!is.null(filter)) { display_filter = TRUE @@ -443,8 +457,7 @@ ae_forestly <- function(outdata, # ---- Build the interactive lt table ---- built <- format_lt_forestly( outdata, - display_soc_toggle = display_soc_toggle, - display_diff_toggle = display_diff_toggle + display_soc_toggle = display_soc_toggle ) # forestly-ae on lt's container scopes cell styles and sizes the table (see # inst/css/forestly-widgets.css); per-column widths from format_lt_forestly() kept. @@ -469,9 +482,9 @@ ae_forestly <- function(outdata, parameter = list( type = "select", choices = param_levels, selected = param_levels[1], label = ae_label, box = FALSE # single-choice only; no custom AE-criteria set - ), - soc_name = "select" + ) ) + if (display_soc_toggle) filter_cfg$soc_name <- "select" for (nm in built$range_cols) filter_cfg[[nm]] <- "range" if (display_filter) { slider_col <- if (filter == "prop") "hide_prop" else "hide_n" diff --git a/R/lt_table.R b/R/lt_table.R index ed1c08d..1f8fd4b 100644 --- a/R/lt_table.R +++ b/R/lt_table.R @@ -31,19 +31,17 @@ #' tested in isolation. #' #' @param outdata An `outdata` object from [format_ae_forestly()]. -#' @param display_soc_toggle Offer the SOC column via the column show/hide menu -#' (starts hidden) instead of dropping it outright. -#' @param display_diff_toggle Offer the numeric risk-difference columns via the -#' column show/hide menu. +#' @param display_soc_toggle Include the SOC column in the table, offered via the +#' column show/hide menu (starts hidden). If `FALSE`, the column is left out of +#' the table data altogether. #' #' @return A list with `x` (an `lt_tbl`) and `hide_menu` (the argument to pass to -#' `lt_interactive(hide=)`: `NULL`, `TRUE`, or a character vector of columns to -#' start hidden). +#' `lt_interactive(hide=)`: `TRUE`, or a character vector of columns to start +#' hidden). #' #' @noRd format_lt_forestly <- function(outdata, - display_soc_toggle = TRUE, - display_diff_toggle = FALSE) { + display_soc_toggle = TRUE) { tbl <- outdata$tbl digits <- outdata$digits %||% 1 m <- outdata$m_group # arms shown as n/(%) columns (incl. Total if displayed) @@ -62,20 +60,21 @@ format_lt_forestly <- function(outdata, # Each figure draws into its own dedicated column via `lt_*(into=)`: lt ships # only the column name (an `add_col` op) and the runtime materializes the - # column, so no duplicated value array travels in the JSON payload. Every + # column, so no duplicated value array is saved in the HTML. Every # proportion / diff stays visible as text (`hide = FALSE` below) and is read by # reference, and the CI bounds come from the hidden `lo_name`/`up_name`. prop_cols <- paste0("prop_", seq_len(ng)) pfig <- "prop_fig" # proportion dot-plot target dfig <- if (nd > 0) "diff_fig" else NULL # risk-difference error-bar target + ci_cols <- c(lo_name, up_name) # Column order of the real data: name, SOC, per-arm n/(%), numeric diffs, # hidden helpers last. The two figure columns are synthesized by the plots and # positioned after SOC by lt_move() below, so the figures lead the numeric # columns as in the forest-plot convention. arm_cols <- as.vector(rbind(name_n, name_prop)) # n_1, prop_1, n_2, prop_2, ... - visible <- c("name", "soc_name", arm_cols, diff_name) - hidden_tail <- c("parameter", "hide_prop", "hide_n", lo_name, up_name) + visible <- c("name", if (display_soc_toggle) "soc_name", arm_cols, diff_name) + hidden_tail <- c("parameter", "hide_prop", "hide_n", ci_cols) tbl <- tbl[, c(visible, hidden_tail), drop = FALSE] # The parameter dropdown filters on the stored value, so ship a plain string @@ -85,7 +84,8 @@ format_lt_forestly <- function(outdata, x <- lt::lt(tbl, auto_format = FALSE, auto_label = FALSE) # Column labels: arm n/(%), numeric diff header per comparison arm. - labels <- list(name = outdata$ae_col_header, soc_name = "SOC") + labels <- list(name = outdata$ae_col_header) + if (display_soc_toggle) labels$soc_name <- "SOC" for (nm in name_n) labels[[nm]] <- "n" for (nm in name_prop) labels[[nm]] <- "(%)" for (k in seq_len(nd)) labels[[diff_name[k]]] <- group[outdata$index_diff[k]] @@ -149,41 +149,34 @@ format_lt_forestly <- function(outdata, x <- lt::lt_label(x, list(dfig, I(outdata$diff_fig_header))) } - # Place the synthesized figure columns right after SOC (before the numeric - # columns); the plots appended them last via `into=`. - x <- lt::lt_move(x, c(pfig, dfig), after = "soc_name") + # Place the synthesized figure columns right after SOC, or the term column when + # SOC is excluded (before the numeric columns); the plots appended them last + # via `into=`. + x <- lt::lt_move(x, c(pfig, dfig), after = if (display_soc_toggle) "soc_name" else "name") # Column widths (px). The synthesized figure columns carry the figure width. - width_cols <- c("name", "soc_name", arm_cols, pfig, diff_name, if (nd > 0) dfig) + width_cols <- c( + "name", if (display_soc_toggle) "soc_name", arm_cols, pfig, diff_name, + if (nd > 0) dfig + ) width_px <- c( - rep(w$term, 2), rep(c(w$n, w$prop), m), w$fig, + rep(w$term, 1 + display_soc_toggle), rep(c(w$n, w$prop), m), w$fig, rep(w$diff, nd), if (nd > 0) w$fig ) x <- lt::lt_width(x, list(width_cols, paste0(width_px, "px"))) - # Decide show/hide handling for SOC and numeric diff columns. - fully_hidden <- c("parameter", "hide_prop", "hide_n", lo_name, up_name) + # Numeric diff columns not shown at start are offered in the show/hide menu + # (SOC is either in the menu or excluded from the data above). + fully_hidden <- c("parameter", "hide_prop", "hide_n", ci_cols) menu_hidden <- character(0) - if (display_soc_toggle) { - menu_hidden <- c(menu_hidden, "soc_name") - } else { - fully_hidden <- c(fully_hidden, "soc_name") - } + if (display_soc_toggle) menu_hidden <- "soc_name" - if (nd > 0 && !diff_shown) { - if (display_diff_toggle) { - menu_hidden <- c(menu_hidden, diff_name) - } else { - fully_hidden <- c(fully_hidden, diff_name) - } - } + if (nd > 0 && !diff_shown) menu_hidden <- c(menu_hidden, diff_name) x <- lt::lt_hide(x, unique(fully_hidden)) - hide_menu <- if (display_soc_toggle || display_diff_toggle) { - if (length(menu_hidden)) menu_hidden else TRUE - } + hide_menu <- if (length(menu_hidden)) menu_hidden else TRUE # Numeric columns shown at start (n, (%), difference) for ae_forestly() sliders. range_cols <- setdiff(c(name_n, name_prop, diff_name), unique(c(fully_hidden, menu_hidden))) diff --git a/man/ae_forestly.Rd b/man/ae_forestly.Rd index 2bc5a10..9e61657 100644 --- a/man/ae_forestly.Rd +++ b/man/ae_forestly.Rd @@ -7,7 +7,7 @@ ae_forestly( outdata, display_soc_toggle = TRUE, - display_diff_toggle = FALSE, + display_diff_toggle = NULL, filter = c("prop", "n"), filter_label = NULL, filter_range = NULL, @@ -20,9 +20,15 @@ ae_forestly( \arguments{ \item{outdata}{An \code{outdata} object created by \code{\link[=format_ae_forestly]{format_ae_forestly()}}.} -\item{display_soc_toggle}{A boolean value to display SOC toggle button.} +\item{display_soc_toggle}{Whether to include the SOC column in the table. If +\code{TRUE}, it is offered in the "Show/Hide columns" menu (hidden by default); if +\code{FALSE}, it is left out of the table entirely. Including it makes the saved +HTML file slightly larger, which only matters for very large data sets.} -\item{display_diff_toggle}{A boolean value to display risk difference toggle button.} +\item{display_diff_toggle}{Deprecated and ignored. The numeric risk-difference +columns are always in the table and, unless \code{"diff"} is in the \code{display} +argument of \code{\link[=format_ae_forestly]{format_ae_forestly()}}, offered in the "Show/Hide columns" menu +(hidden by default).} \item{filter}{The variable the incidence slider (the "Incidence (\%) in One or More Treatment Groups" chip in the control bar) filters on: \code{"prop"} for diff --git a/tests/testthat/test-ae_forestly.R b/tests/testthat/test-ae_forestly.R index 8cc9a07..4a16b93 100644 --- a/tests/testthat/test-ae_forestly.R +++ b/tests/testthat/test-ae_forestly.R @@ -43,7 +43,7 @@ test_that("ae_forestly(): no incidence filter when filter is NULL", { expect_false(grepl("One or More Treatment Groups", html_text, fixed = TRUE)) }) -test_that("ae_forestly(): both diff-toggle settings render without error", { +test_that("ae_forestly(): deprecated display_diff_toggle warns but still renders", { outdata <- meta_ae_test() |> prepare_ae_forestly( population = "apat", @@ -52,6 +52,9 @@ test_that("ae_forestly(): both diff-toggle settings render without error", { ) |> format_ae_forestly(display = c("n", "prop", "fig_prop", "fig_diff")) - expect_s3_class(ae_forestly(outdata, display_diff_toggle = FALSE), "shiny.tag.list") - expect_s3_class(ae_forestly(outdata, display_diff_toggle = TRUE), "shiny.tag.list") + expect_warning( + res <- ae_forestly(outdata, display_diff_toggle = TRUE), + "deprecated" + ) + expect_s3_class(res, "shiny.tag.list") }) diff --git a/tests/testthat/test-lt_table.R b/tests/testthat/test-lt_table.R index 88e2f74..2bf1fe6 100644 --- a/tests/testthat/test-lt_table.R +++ b/tests/testthat/test-lt_table.R @@ -17,23 +17,22 @@ test_that("format_lt_forestly(): returns an lt_tbl and a hide-menu spec", { expect_true("hide_menu" %in% names(built)) }) -test_that("format_lt_forestly(): SOC toggle controls the hide menu vs. hard hide", { +test_that("format_lt_forestly(): SOC toggle offers or excludes the SOC column", { out <- helper_lt_outdata() - # No toggles -> no column-visibility menu at all. - built_none <- format_lt_forestly(out, display_soc_toggle = FALSE, display_diff_toggle = FALSE) - expect_null(built_none$hide_menu) - # SOC toggle -> SOC column offered in the menu (starts hidden). - built_soc <- format_lt_forestly(out, display_soc_toggle = TRUE, display_diff_toggle = FALSE) - expect_true("soc_name" %in% built_soc$hide_menu) + expect_true("soc_name" %in% format_lt_forestly(out, display_soc_toggle = TRUE)$hide_menu) + + # Excluded: not in the menu, and nowhere in the rendered table. + expect_false("soc_name" %in% format_lt_forestly(out, display_soc_toggle = FALSE)$hide_menu) + html <- paste(as.character(ae_forestly(out, display_soc_toggle = FALSE)), collapse = "") + expect_false(grepl("soc_name", html, fixed = TRUE)) }) -test_that("format_lt_forestly(): diff toggle adds the numeric diff columns to the menu", { +test_that("format_lt_forestly(): diff columns are offered in the show/hide menu", { out <- helper_lt_outdata() - built <- format_lt_forestly(out, display_soc_toggle = TRUE, display_diff_toggle = TRUE) + built <- format_lt_forestly(out) # diff columns are named after the comparison arms (diff_). - diff_cols <- out$diff_name - expect_true(all(diff_cols %in% built$hide_menu)) + expect_true(all(out$diff_name %in% built$hide_menu)) }) diff --git a/vignettes/customize-toggle-buttons.Rmd b/vignettes/customize-toggle-buttons.Rmd index 2975e95..b2085cf 100644 --- a/vignettes/customize-toggle-buttons.Rmd +++ b/vignettes/customize-toggle-buttons.Rmd @@ -79,14 +79,13 @@ meta <- meta_adam(population = adsl, observation = adae) |> # Step 2: toggle risk difference columns -Users can control the display of risk difference columns using the `display_diff_toggle = ...` argument in the `ae_forestly()` function. +The numeric risk difference columns (`diff`) are always offered in the "Show/Hide columns" menu above the table, hidden by default unless `"diff"` is in the `display` argument of `format_ae_forestly()`. (The `display_diff_toggle` argument of `ae_forestly()` is deprecated and ignored.) -In the example below, we enable the risk difference toggle button by setting `display_diff_toggle = TRUE`. This adds an interactive "Show/Hide Risk Difference" button above the table, allowing users to dynamically show or hide all risk difference related columns, including the difference values (`diff`) and the risk difference visualization (`fig_diff`). +The `display_soc_toggle = ...` argument controls the SOC column: if `TRUE`, it is included in the table and offered in the same menu (hidden by default); if `FALSE`, it is left out of the table entirely. Leaving it out makes the saved HTML file slightly smaller, which only matters for very large data sets. ```{r} meta |> prepare_ae_forestly() |> format_ae_forestly(display = c("n", "prop", "fig_prop", "fig_diff", "diff")) |> - ae_forestly(display_diff_toggle = TRUE, - display_soc_toggle = TRUE) + ae_forestly(display_soc_toggle = TRUE) ``` From c67b53fe366f7ea69a5c3d3eb73892abd5a4c242 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Thu, 5 Nov 2026 13:14:33 -0500 Subject: [PATCH 2/3] Make format_lt_forestly() honor `display` for figures, n, and prop The reactable version hid the proportion/difference figures and the n/(%) columns when absent from `format_ae_forestly(display=)`; the lt version ignored them. Build each figure only when listed, and include n/prop columns only when listed (proportions are still carried, hidden, when the dot plot reads them; CI bounds ship only with the error bar). Co-Authored-By: Claude Code --- R/lt_table.R | 78 ++++++++++++++++++++-------------- tests/testthat/test-lt_table.R | 24 +++++++++++ 2 files changed, 71 insertions(+), 31 deletions(-) diff --git a/R/lt_table.R b/R/lt_table.R index 1f8fd4b..ac4cbf9 100644 --- a/R/lt_table.R +++ b/R/lt_table.R @@ -56,7 +56,8 @@ format_lt_forestly <- function(outdata, lo_name <- outdata$ci_lower_name up_name <- outdata$ci_upper_name nd <- length(diff_name) - diff_shown <- "diff" %in% outdata$display + display <- outdata$display + diff_shown <- "diff" %in% display # Each figure draws into its own dedicated column via `lt_*(into=)`: lt ships # only the column name (an `add_col` op) and the runtime materializes the @@ -64,15 +65,27 @@ format_lt_forestly <- function(outdata, # proportion / diff stays visible as text (`hide = FALSE` below) and is read by # reference, and the CI bounds come from the hidden `lo_name`/`up_name`. prop_cols <- paste0("prop_", seq_len(ng)) - pfig <- "prop_fig" # proportion dot-plot target - dfig <- if (nd > 0) "diff_fig" else NULL # risk-difference error-bar target - ci_cols <- c(lo_name, up_name) + # A figure is built only when listed in `display`; the CI bounds are carried + # only for the error bar. + pfig <- if ("fig_prop" %in% display) "prop_fig" # dot-plot target + dfig <- if (nd > 0 && "fig_diff" %in% display) "diff_fig" # error-bar target + ci_cols <- if (!is.null(dfig)) c(lo_name, up_name) # Column order of the real data: name, SOC, per-arm n/(%), numeric diffs, # hidden helpers last. The two figure columns are synthesized by the plots and # positioned after SOC by lt_move() below, so the figures lead the numeric # columns as in the forest-plot convention. - arm_cols <- as.vector(rbind(name_n, name_prop)) # n_1, prop_1, n_2, prop_2, ... + # + # `n` / `prop` shown only when listed in `display`. The per-arm proportions are + # still carried, hidden, when the dot plot reads them; otherwise they, and any + # unshown column, are left out of the data. + show_n <- if ("n" %in% display) name_n + show_prop <- if ("prop" %in% display) name_prop + prop_hidden <- if (!is.null(pfig)) setdiff(prop_cols, show_prop) + arm_cols <- intersect( # n_1, prop_1, n_2, prop_2, ... + as.vector(rbind(name_n, name_prop)), c(show_n, show_prop, prop_hidden) + ) + shown_arm_cols <- setdiff(arm_cols, prop_hidden) visible <- c("name", if (display_soc_toggle) "soc_name", arm_cols, diff_name) hidden_tail <- c("parameter", "hide_prop", "hide_n", ci_cols) tbl <- tbl[, c(visible, hidden_tail), drop = FALSE] @@ -86,13 +99,15 @@ format_lt_forestly <- function(outdata, # Column labels: arm n/(%), numeric diff header per comparison arm. labels <- list(name = outdata$ae_col_header) if (display_soc_toggle) labels$soc_name <- "SOC" - for (nm in name_n) labels[[nm]] <- "n" - for (nm in name_prop) labels[[nm]] <- "(%)" + for (nm in show_n) labels[[nm]] <- "n" + for (nm in show_prop) labels[[nm]] <- "(%)" for (k in seq_len(nd)) labels[[diff_name[k]]] <- group[outdata$index_diff[k]] x <- lt::lt_label(x, labels) # Numeric formatting: proportions wrapped as "(x.x)", diffs to `digits`. - x <- lt::lt_format(x, name_prop, decimals = digits, prefix = "(", suffix = ")") + if (length(show_prop)) { + x <- lt::lt_format(x, show_prop, decimals = digits, prefix = "(", suffix = ")") + } if (nd > 0) x <- lt::lt_format(x, diff_name, decimals = digits) # Per-arm treatment-group spanners "
(N=...)" over each n/(%) pair. @@ -101,7 +116,8 @@ format_lt_forestly <- function(outdata, "%s
(N=%s)
", group[i], outdata$n_pop[i], group[i], outdata$n_pop[i] ) - x <- lt::lt_spanner(x, I(header), c(name_n[i], name_prop[i])) + arm_i <- intersect(c(name_n[i], name_prop[i]), shown_arm_cols) + if (length(arm_i)) x <- lt::lt_spanner(x, I(header), arm_i) } if (diff_shown && nd > 0) { x <- lt::lt_spanner(x, I(outdata$diff_col_header), diff_name) @@ -110,18 +126,20 @@ format_lt_forestly <- function(outdata, # Inline proportion dot plot: one dot per arm on a shared scale, footer legend # keyed by arm color. Dots are staggered onto separate tracks so near-equal # per-arm proportions stay distinguishable (as in the original forest plot). - x <- lt::lt_dotplot( - x, prop_cols, - into = pfig, - color = outdata$fig_prop_color, - labels = group[seq_len(ng)], - limits = outdata$fig_prop_range, - width = w$fig, - stagger = TRUE, - axis = TRUE, - hide = FALSE # the per-arm proportions stay visible as numeric columns - ) - x <- lt::lt_label(x, list(pfig, "AE Proportion (%)")) + if (!is.null(pfig)) { + x <- lt::lt_dotplot( + x, prop_cols, + into = pfig, + color = outdata$fig_prop_color, + labels = group[seq_len(ng)], + limits = outdata$fig_prop_range, + width = w$fig, + stagger = TRUE, + axis = TRUE, + hide = FALSE # the per-arm proportions stay visible as numeric columns + ) + x <- lt::lt_label(x, list(pfig, "AE Proportion (%)")) + } # Inline risk-difference error-bar: one point + 95% CI per comparison, stacked, # shared scale, zero reference line, favor-direction axis label. Color + legend @@ -132,7 +150,7 @@ format_lt_forestly <- function(outdata, }) eb_color <- if (nd > 1) outdata$fig_diff_color else FALSE eb_labels <- if (nd > 1) group[outdata$index_diff] else NULL - if (nd > 0) { + if (!is.null(dfig)) { x <- do.call(lt::lt_errorbar, c( list(x), eb_series, list( @@ -152,22 +170,20 @@ format_lt_forestly <- function(outdata, # Place the synthesized figure columns right after SOC, or the term column when # SOC is excluded (before the numeric columns); the plots appended them last # via `into=`. - x <- lt::lt_move(x, c(pfig, dfig), after = if (display_soc_toggle) "soc_name" else "name") + figs <- c(pfig, dfig) + if (length(figs)) x <- lt::lt_move(x, figs, after = if (display_soc_toggle) "soc_name" else "name") # Column widths (px). The synthesized figure columns carry the figure width. - width_cols <- c( - "name", if (display_soc_toggle) "soc_name", arm_cols, pfig, diff_name, - if (nd > 0) dfig - ) + width_cols <- c("name", if (display_soc_toggle) "soc_name", arm_cols, pfig, diff_name, dfig) width_px <- c( - rep(w$term, 1 + display_soc_toggle), rep(c(w$n, w$prop), m), w$fig, - rep(w$diff, nd), if (nd > 0) w$fig + rep(w$term, 1 + display_soc_toggle), ifelse(arm_cols %in% name_n, w$n, w$prop), + rep(w$fig, length(pfig)), rep(w$diff, nd), rep(w$fig, length(dfig)) ) x <- lt::lt_width(x, list(width_cols, paste0(width_px, "px"))) # Numeric diff columns not shown at start are offered in the show/hide menu # (SOC is either in the menu or excluded from the data above). - fully_hidden <- c("parameter", "hide_prop", "hide_n", ci_cols) + fully_hidden <- c("parameter", "hide_prop", "hide_n", ci_cols, prop_hidden) menu_hidden <- character(0) if (display_soc_toggle) menu_hidden <- "soc_name" @@ -179,7 +195,7 @@ format_lt_forestly <- function(outdata, hide_menu <- if (length(menu_hidden)) menu_hidden else TRUE # Numeric columns shown at start (n, (%), difference) for ae_forestly() sliders. - range_cols <- setdiff(c(name_n, name_prop, diff_name), unique(c(fully_hidden, menu_hidden))) + range_cols <- setdiff(c(shown_arm_cols, diff_name), unique(c(fully_hidden, menu_hidden))) list(x = x, hide_menu = hide_menu, range_cols = range_cols) } diff --git a/tests/testthat/test-lt_table.R b/tests/testthat/test-lt_table.R index 2bf1fe6..dc3422f 100644 --- a/tests/testthat/test-lt_table.R +++ b/tests/testthat/test-lt_table.R @@ -36,3 +36,27 @@ test_that("format_lt_forestly(): diff columns are offered in the show/hide menu" # diff columns are named after the comparison arms (diff_). expect_true(all(out$diff_name %in% built$hide_menu)) }) + +test_that("ae_forestly(): figures appear only when listed in `display`", { + m <- meta_ae_test() |> + prepare_ae_forestly(population = "apat", observation = "wk12", parameter = "any;rel;ser") + has_figs <- function(display) { + html <- paste(as.character(ae_forestly(format_ae_forestly(m, display = display))), collapse = "") + c(prop = grepl("AE Proportion (%)", html, fixed = TRUE), + diff = grepl("Risk Difference", html, fixed = TRUE)) + } + expect_equal(has_figs(c("n", "prop", "fig_prop", "fig_diff")), c(prop = TRUE, diff = TRUE)) + expect_equal(has_figs(c("n", "prop", "fig_prop")), c(prop = TRUE, diff = FALSE)) + expect_equal(has_figs(c("n", "prop", "fig_diff")), c(prop = FALSE, diff = TRUE)) + expect_equal(has_figs(c("n", "prop")), c(prop = FALSE, diff = FALSE)) +}) + +test_that("format_lt_forestly(): n and (%) columns follow `display`", { + m <- meta_ae_test() |> + prepare_ae_forestly(population = "apat", observation = "wk12", parameter = "any;rel;ser") + shown <- function(display) format_lt_forestly(format_ae_forestly(m, display = display))$range_cols + + expect_false(any(grepl("^(n|prop)_", shown("fig_prop")))) + expect_true(length(shown("n")) > 0 && all(grepl("^n_", shown("n")))) + expect_true(any(grepl("^prop_", shown("prop")))) +}) From 755f4c3af8ed93f1b596694df9d715de3eb7e752 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Thu, 5 Nov 2026 13:31:43 -0500 Subject: [PATCH 3/3] reword [ci skip] --- DESCRIPTION | 2 +- R/ae_forestly.R | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fd9246c..e62f868 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: forestly Title: Interactive Forest Plot -Version: 0.1.8 +Version: 0.1.9 Authors@R: c( person("Yilong", "Zhang", role = c("aut")), person("Benjamin", "Wang", role = c("aut")), diff --git a/R/ae_forestly.R b/R/ae_forestly.R index b9603b9..a9baddf 100644 --- a/R/ae_forestly.R +++ b/R/ae_forestly.R @@ -165,13 +165,10 @@ ae_forestly <- function(outdata, max_page = NULL, download_button = FALSE, width = NULL) { - if (!is.null(display_diff_toggle)) { - warning( - "`display_diff_toggle` is deprecated and ignored; the risk-difference ", - "columns are always offered in the Show/Hide columns menu.", - call. = FALSE - ) - } + if (!is.null(display_diff_toggle)) warning( + "`display_diff_toggle` is deprecated and will be removed in future; ", + "the risk-difference columns are always offered in the Show/Hide columns menu." + ) # Set filter parameter if (!is.null(filter)) {