1

您好我想知道是否有一种方法可以保存使用 gt 包包创建的表格并用作具有透明背景的图像?

下面是一些示例代码,它创建一个 gt() 表并将该表保存为 png,但不透明

  filter((Sepal.Length==5.1 & Species=='versicolor')) %>%
  select(Sepal.Length,Sepal.Width,Petal.Length,Petal.Width) %>%
  gt() %>%
  tab_spanner(label = "Sepal", columns = vars(Sepal.Length, Sepal.Width)) %>%
  tab_spanner(label = "Petal", columns = vars(Petal.Length, Petal.Width)) %>% 
  tab_options(
    table.background.color = "transparent",
    column_labels.font.size = 10.5,
    table.font.size = 10,
    heading.title.font.size  = 24,
    heading.title.font.weight = 'bold',
    heading.subtitle.font.size = 11,
    table.font.color = 'white',
    table.border.top.color = "#0D2549",
    data_row.padding = px(2), 
    footnotes.font.size = 8,
    source_notes.font.size = 9,
    footnotes.padding = px(1), 
  ) %>%
  opt_table_font(
    font = list(
      google_font("Chivo"),
      default_fonts()
    )
  ) %>%
  gtsave("Image Name.png")
4

1 回答 1

1

这是我在我的 Shiny App 中使用 CSS 颜色使 GT 表格背景透明的内容。

tab_options(
    table.background.color = "#FFFFFF00",
    column_labels.font.size = px(10),
    column_labels.font.weight = "bold",
    table.font.color = "white",
    table.font.size = px(12L)
)

这是桌子的样子。请注意,Shiny App 的背景是黑色的,因此表格显示为黑色(尽管它实际上是透明的)。

闪亮应用程序中的 GT 表

于 2021-11-17T12:28:27.687 回答