pythonrwkhtmltopdfgtwkhtmltoimage

Is there a way to render gt tables as PNGs with (a) no browser and (b) without wkhtmltopdf/wkhtmltoimage? (R/Python)


I have a really pretty gt table that we'd like to automate production of. Running this on our remote server has some limitations: enterprise policy is that no browsers, headless or otherwise, may be installed on the server; the admin has been unwilling to install wkhtmltopdf.

So I can either run this locally, which I'd rather avoid, or I can schedule it to crank out an HTML table, which is a pain for the person who actually uses these images. Rendering the gt_tbl using ggplot destroys a lot of the formatting that was done.

The R script that generates the table is set up now to output an html table. I'm open to solutions in R or Python that can run after the table is generated.

Thanks!


Solution

  • Figured it out!

    foo <- <a gt_tbl object>
    
    library(ggplot2)
    library(ggplotify)
    library(rsvg) #required to render SVG cells
    
    foo_1 <- as_gtable(foo)
    foo_2 <- as.ggplot(foo_1)
    ggsave('path/to/file.png', foo_2)