0

I am trying to convert an html table created in R via the huxtable package to a png file using webshot2::webshot. Unfortunately, the very right side of the output seems to get trimmed off and I can't figure out how to fix this generically.

I don't want to manually tweak the cliprect parameter because I'll need to do this for many tables and its not scalable if its not generic. However, it is possible to achieve it with this parameter so I wonder why its failing with the other workflow.

Here's an example illustrating the problem:

library(magrittr)
library(huxtable)
set.seed(1337)

data <- matrix(rnorm(25), 35, 10)
my_hux <- as_hux(data) %>%
  set_outer_borders(0.4) %>%
  map_background_color(by_rows("grey95", "white")) %>%
  map_text_color(by_quantiles(c(0.1, 0.9), c("red", "black", "green3")))

quick_html(my_hux, file = "ahuxtable.html", open = FALSE)

webshot2::webshot(url = "ahuxtable.html", file = "ahuxtable.png",
                  zoom = 5, selector = "table")

I tried this with webshot::webshot, however the webshot package seems to be webshot2's predecessor so I'd prefer a webshot2 solution if there is one.

Patrick
  • 742
  • 7
  • 19
  • Just out of interest can you tell me why you want to do this? – dash2 Aug 02 '22 at 07:17
  • I am producing HTML reports via RMarkdown, which incorporate huxtables. For the primary HTML everything works fine. A secondary output are PowerPoint slides. I tried doing this with RMarkdown too, however, the tables in the resultsing pptx get a little garbled stylewise. That is, column widths etc change and a lot of manual post-processing becomes necessary. Thus I have opted to produce static png versions of the huxtables which are then linked in the pptx. The static version looks exactly like in the HTML report. Currently I have a working `webshot` solution. – Patrick Aug 02 '22 at 10:30

0 Answers0