如何将多个html(有线)表合并为一个图像? [英] how to combine multiple html (kable) tables into one image?

查看:84
本文介绍了如何将多个html(有线)表合并为一个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将几个kable表合并到一个图像中. 像这样:

I would like to combine several kable tables into one single image. Something like:

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"))

,然后在图像中的table2顶部放置table1:

and put table1 on top of table2 in an image:

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

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

However, this does not work. How can I do that? Thanks!

推荐答案

基于这个答案,看来cat函数可以将多个表组合成html.所以您可以kable(c(table1, table2), "html") %>% cat(., file = "P:/mytable/table.html")然后将html转换为jpg

Based on this answer, it looks like the function cat could work to combine multiple tables into html. So you could do kable(c(table1, table2), "html") %>% cat(., file = "P:/mytable/table.html") And then convert the html to a jpg

这篇关于如何将多个html(有线)表合并为一个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆