I was wondering if somebody knows any alternative method to export ggvis objects to PNG. Can be implemented on Linux or Windows.
Thanks
I found several ways, I'm posting the one that is more straight forward.
library(ggvis)
library(XML)
library(webshot)
library(htmltools)
outfile <- mtcars %>% ggvis(~wt, ~mpg) %>% layer_smooths() %>% set_options(width = 1200, height = 800) %>% view_static() %>% html_print( background = "white", viewer = getOption("viewer", utils::browseURL))
webst <- htmlParse(outfile, asText=FALSE)
showMethods(class=class(webst), where=search())
webst <- as(webst, "character")
class(webst)
id <- webst %>% sub(pattern = "-container.*", replacement ="") %>% sub(pattern = ".*plot_", replacement ="")
selec <- paste0("#plot_", id, " > div > svg")
webshot(outfile, "test_webshot8.png", selector = selec)
If you have suggestions how to simplify or a better method will be appreciated.