Skip to content

Commit

Permalink
Merge pull request #1533 from rstudio/cols-nanoplot-autohide
Browse files Browse the repository at this point in the history
Add the `autohide` argument to `cols_nanoplot()`
  • Loading branch information
rich-iannone authored Jan 13, 2024
2 parents 55e3d6a + 03d7880 commit aff3462
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
38 changes: 34 additions & 4 deletions R/modify_columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,16 @@ cols_add <- function(
#' *x*-axis data), which is useful in those cases where the nanoplot data
#' should be compared across rows.
#'
#' @param autohide *Automatically hide the `columns`/`columns_x_vals` column(s)*
#'
#' `scalar<logical>` // *default:* `TRUE`
#'
#' An option to automatically hide any columns specified in `columns` and also
#' `columns_x_vals` (if used). Any columns with their state changed to
#' 'hidden' will behave the same as before, they just won't be displayed in
#' the finalized table. Should you want to have these 'input' columns be
#' viewable, set `autohide = FALSE`.
#'
#' @param columns_x_vals *Columns containing values for the optional x variable*
#'
#' `<column-targeting expression>` // *default:* `NULL` (`optional`)
Expand Down Expand Up @@ -2428,7 +2438,7 @@ cols_add <- function(
#' gt(rowname_col = "test") |>
#' tab_header("Partial summary of daily tests performed on YF patient") |>
#' tab_stubhead(label = md("**Test**")) |>
#' cols_hide(columns = c(starts_with("norm"), starts_with("day"))) |>
#' cols_hide(columns = starts_with("norm")) |>
#' fmt_units(columns = units) |>
#' cols_nanoplot(
#' columns = starts_with("day"),
Expand Down Expand Up @@ -2472,6 +2482,7 @@ cols_add <- function(
#' cols_nanoplot(
#' columns = c(chicken, classic, supreme, veggie),
#' plot_type = "bar",
#' autohide = FALSE,
#' new_col_name = "pizzas_sold",
#' new_col_label = "Sales by Type",
#' options = nanoplot_options(
Expand Down Expand Up @@ -2512,12 +2523,14 @@ cols_add <- function(
#' cols_nanoplot(
#' columns = starts_with("population"),
#' reference_line = "median",
#' autohide = FALSE,
#' new_col_name = "population_plot",
#' new_col_label = md("*Change*")
#' ) |>
#' cols_nanoplot(
#' columns = starts_with("density"),
#' plot_type = "bar",
#' autohide = FALSE,
#' new_col_name = "density_plot",
#' new_col_label = md("*Change*")
#' ) |>
Expand Down Expand Up @@ -2585,7 +2598,6 @@ cols_add <- function(
#' data_bar_fill_color = "DarkOrange"
#' )
#' ) |>
#' cols_hide(columns = matches("0")) |>
#' tab_options(
#' table.width = px(400),
#' column_labels.hidden = TRUE
Expand Down Expand Up @@ -2637,7 +2649,6 @@ cols_add <- function(
#' title = md("Pizzas sold on **January 1, 2015**"),
#' subtitle = "Between the opening hours of 11:30 to 22:30"
#' ) |>
#' cols_hide(columns = c(date_time, sold)) |>
#' cols_nanoplot(
#' columns = sold,
#' columns_x_vals = date_time,
Expand Down Expand Up @@ -2695,7 +2706,7 @@ cols_add <- function(
#' plot_type = "boxplot",
#' options = nanoplot_options(y_val_fmt_fn = function(x) hms::as_hms(x))
#' ) |>
#' cols_hide(columns = c(time, is_weekend)) |>
#' cols_hide(columns = is_weekend) |>
#' cols_width(everything() ~ px(250)) |>
#' cols_align(align = "center", columns = nanoplots) |>
#' cols_align(align = "left", columns = date) |>
Expand Down Expand Up @@ -2733,6 +2744,7 @@ cols_nanoplot <- function(
plot_height = "2em",
missing_vals = c("gap", "zero", "remove"),
autoscale = FALSE,
autohide = TRUE,
columns_x_vals = NULL,
reference_line = NULL,
reference_area = NULL,
Expand Down Expand Up @@ -2986,6 +2998,24 @@ cols_nanoplot <- function(
locations = cells_body(columns = validated_new_col_name)
)

if (isTRUE(autohide)) {

data <-
cols_hide(
data = data,
columns = resolved_columns
)

if (length(resolved_columns_x) > 0) {

data <-
cols_hide(
data = data,
columns = resolved_columns_x
)
}
}

data
}

Expand Down
20 changes: 16 additions & 4 deletions man/cols_nanoplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aff3462

Please sign in to comment.