gtExtras icon indicating copy to clipboard operation
gtExtras copied to clipboard

gt_badge conditional on variables

Open aghaynes opened this issue 10 months ago • 1 comments

Prework

  • [x] Search for duplicates among the existing issues (both open and closed).

Proposal

It would be nice to be able to set badges on only certain rows of a gt table. For instance, here's an example with missings

d <- tibble::tribble(
  ~a, ~b,
  "a", 1,
  "b", 2,
  "c", NA,
  "d", NA,
)

gt(d) |> 
  gt_badge(b,
           palette = c("red", "blue", "green")) |>
  sub_missing(missing_text = "")

image

There are two issues here. Firstly, the <br /> tag, which I guess might be a bug, and secondly, the badge itself on those <br /> tags, which would rather be blank instead.

It would be great to be able to do something like

gt(d) |> 
  gt_badge(b,
           palette = c("red", "blue"),
           rows = !is.na(b)) |>
  sub_missing(missing_text = "")

aghaynes avatar Apr 09 '24 20:04 aghaynes