我创建了一个亮丽的应用程序,现在我想将图表输出到PDF格式。那么,在R中是否有将GoogleVis图表打印为PDF的方法?
我知道直接打印是不可能的,正如帮助页面中所述。但是否有一种方法可以打印静态图像(类似于截图)?如果可能的话,无需使用sweave/knitr?
提前感谢您。
您可以使用wkhtmltopdf来实现此操作,需要安装并可能将其添加到系统路径中。我已经在其他googlevis对象中使其正常工作,在某些情况下,我不需要--enable-javascript --javascript-delay
选项....
output$downloadmap <- downloadHandler("mymap.pdf" ,
content = function(file) {
#print gmap googlevis R object to a html file
print(gmap, file="gmap.html")
#call to wkhtmltopdf installed on server/pc to convert html file to pdf.
#add a delay otherwise (i got an) empty plot
system("wkhtmltopdf --enable-javascript --javascript-delay 2000 gmap.html gmap.pdf")
#copy pdf file to output
file.copy("gmap.pdf", file)
#remove created files from local storage
file.remove("gmap.pdf")
file.remove("gmap.html")
}
)