Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the autohide argument to cols_nanoplot() #1533

Merged
merged 6 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading