简体   繁体   English

在Google中将Googlevis图表打印为pdf

[英]Print a Googlevis chart to pdf in R

I created a shiny app and now i want to plot a chart to pdf. 我创建了一个闪亮的应用程序,现在我想绘制一个图表到PDF格式。 So, is there any way to print a googlevis Chart to pdf in R. 那么,有没有办法在R中将googlevis图表打印为pdf

I know its not possible directly, as stated in the help pages. 我知道它不可能直接,如帮助页面中所述。 But is there a way to print a static image (similar to a screenshot)? 但有没有办法打印静态图像(类似于截图)? If possible without sweave/knitr? 如果可能没有sweave / knitr?

Thank you in advance 先感谢您

You can do this using wkhtmltopdf, which you need to install and possibly add to your system path. 您可以使用wkhtmltopdf执行此操作,您需要安装并添加到系统路径中。 I have got this working for other googlevis objects, where in some cases I did not need the --enable-javascript --javascript-delay option.... 我有这个工作的其他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")
  }
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM