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

gt_badge conditional on variables #123

Open
1 task done
aghaynes opened this issue Apr 9, 2024 · 1 comment
Open
1 task done

gt_badge conditional on variables #123

aghaynes opened this issue Apr 9, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@aghaynes
Copy link

aghaynes commented Apr 9, 2024

Prework

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 = "")
@jthomasmock
Copy link
Owner

I have this working locally now:

library(gtExtras)

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

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

image

@jthomasmock jthomasmock added the enhancement New feature or request label Aug 23, 2024
@jthomasmock jthomasmock added this to the 0.6 milestone Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants