首页 > 解决方案 > 使用 formattable 的更多样式问题

问题描述

在下表中,如何删除加拿大行和世界行之间的线?

另外,如何从列标题中删除粗体(即 1980、2019、Change)?

这与建议的链接不同,我想知道是否有以下形式的解决方案:

# Define styles
row_emphasis <- formatter("span", style = ~style("font.weight" = "bold", "font.size" = "18px"))
make_non_bold <- formatter("span", style = "font-style:italic; font-weight:normal")


 # Apply styles
 formattable(can_world_table, list(
      area(row = 1) ~ row_emphasis,
      # column headers # ~ make_non_bold
      ))

至于关于删除行之间的线的部分,下面的建议答案并没有解决我的问题。此代码在 Canada 和标题行之间添加了另一行:

row_emphasis <- formatter("span", style = ~style("font.weight" = "bold", "font.size" = "18px", "border-top: 1px solid green"))

library(tidyverse)
library(formattable)

target_year = 1980
current_year = 2019

can_target = 20.464
can2019 = 37.786

world_target = 6123
world2019 = 7456

can_change <- (can2019 - can_target) / can_target
world_change <- (world2019 - world_target) / world_target

can_world_table <- tibble(
  region = c("Canada", "World"),
  ty = c(round(can_target, digits = 0), round(world_target, digits = -2)),
  cy = c(can2019, round(world2019, digits = -2)),
  change = percent(c(can_change, world_change), 0)
) %>% 
  set_names(c("", target_year, current_year, "Change"))


can_world_table

can_world_table <- tibble(
  region = c("Canada", "World"),
  ty = c(can_target, format(round(world_target, digits = -2), big.mark = ",")),
  cy = c(can2019, format(round(world2019, digits = -2), big.mark = ",")),
  change = percent(c(can_change, world_change), 0)
) %>% 
  set_names(c(" ", target_year, current_year, "Change")) 

row_emphasis <- formatter("span", style = ~style("font.weight" = "bold", "font.size" = "18px"))
formattable(can_world_table, list(
  area(row = 1) ~ row_emphasis
  ))

标签: rformattable

解决方案


推荐阅读