简体   繁体   English

带有行过滤器的 gt 表着色整列

[英]gt table coloring full column with row filter

Has anyone had the following issue with gt table?有人对 gt 表有以下问题吗?

Regardless of the value I set for the tab style row argument the whole column gets hit with the color argument.无论我为选项卡样式行参数设置的值如何,整个列都会被颜色参数击中。 I only want the "Paid Per Episode" column to color it blue when it is greater than 33000.我只希望“每集付费”列在大于 33000 时将其着色为蓝色。

Could this be something with R markdown?这可能与 R markdown 有关吗?

hip_dt_epsd_table %>% 
  rename(State = JUR_ST_ABBR_PRIM, Episodes = epsd_count, "Paid Per Episode" = pd_per_epsd, "Episodes Outlier" = epsd_outlier, 
         "Paid Per Episode Outlier" = pd_epsd_outlier, 
         "Episodes 99th Percentile" = epsd_count_99th) %>%
  gt() %>% 
  fmt_currency(columns=vars("Paid Per Episode","Paid Per Episode Outlier")) %>%
  fmt_number(columns=vars("Episodes","Episodes Outlier","Episodes 99th Percentile"),sep_mark=",", drop_trailing_zeros = TRUE) %>%
  tab_style(
    style = cell_fill(color = "lightblue"),
    locations = cells_body(
      columns = "Paid Per Episode",
      row = "Paid Per Episode" > 33000))

Since you did not provide an example I have used mtcars dataset.由于您没有提供示例,因此我使用mtcars数据集。

library(gt)

mtcars %>%
  gt() %>%
  tab_style(style = cell_fill(color = "lightblue"),
            locations = cells_body(columns = "disp",rows = disp > 250))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM