Visnetwork plot is not saved as png image

跟風遠走 提交于 2021-02-19 06:06:29

问题


I plot a simple network using visNetwork but when I try to save it as png I get an empty image as a result.

png("ex.png")
require(visNetwork, quietly = TRUE)
# minimal example
nodes <- data.frame(id = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))
visNetwork(nodes, edges, width = "100%")
dev.off()

回答1:


You can save the network as html and then capture the content of that file:

nodes <- data.frame(id = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))

library(visNetwork)
plot<- visNetwork(nodes, edges, width = "100%")

html_name <- tempfile(fileext = ".html")
visSave(plot, html_name)

library(webshot); #webshot::install_phantomjs() #in case phantomjs was not installed 

webshot(html_name, zoom = 2, file = "ex.png")


来源:https://stackoverflow.com/questions/56654452/visnetwork-plot-is-not-saved-as-png-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!