【问题标题】:how to combine multiple html (kable) tables into one image?如何将多个 html (kable) 表组合成一张图像?
【发布时间】:2019-01-03 15:23:03
【问题描述】:

我想将多个kable 表合并到一个图像中。 比如:

library(knitr)
library(kableExtra)
dt <- mtcars[1:5, 1:4]

# first table
table1 <- kable(dt, format = "html", caption = "Demo Table") %>%
  kable_styling(bootstrap_options = "striped",
                full_width = F) %>%
  add_header_above(c(" ", "Group 1" = 2, "Group 2[note]" = 2)) %>%
  add_footnote(c("table footnote"))

# second table
table2 <- kable(dt, format = "html", caption = "Demo Table") %>%
  kable_styling(bootstrap_options = "striped",
                full_width = F) %>%
  add_header_above(c(" ", "Group 1" = 2, "Group 2[note]" = 2)) %>%
  add_footnote(c("table footnote"))

并将table1 放在图像中的table2 之上:

bind_rows(table1, table2) %>% 
  kable_as_image(., filename = 'P:/mytable/table')

但是,这不起作用。我怎样才能做到这一点? 谢谢!

【问题讨论】:

    标签: r knitr kable


    【解决方案1】:

    基于this answer,看起来函数 cat 可以将多个表合并到 html 中。所以你可以做kable(c(table1, table2), "html") %&gt;% cat(., file = "P:/mytable/table.html") 然后将html转换为jpg

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      相关资源
      最近更新 更多