在R中将Googlevis图表打印成PDF

4
我创建了一个亮丽的应用程序,现在我想将图表输出到PDF格式。那么,在R中是否有将GoogleVis图表打印为PDF的方法? 我知道直接打印是不可能的,正如帮助页面中所述。但是否有一种方法可以打印静态图像(类似于截图)?如果可能的话,无需使用sweave/knitr? 提前感谢您。
1个回答

2

您可以使用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")
  }
)

当您将Googlevis图表插入PDF时,它们是交互式的还是静态图像? - user1471980
所以不需要googlevis,ggplot就足够了。 - user1471980
@user1471980,ggplot在你的shiny应用程序中不会提供与googlevis相同的鼠标悬停交互式内容。你可以在点击下载按钮时打印ggplot并返回给用户,但它不会匹配显示的googlvis图。 - guyabel
@jdharrison 我明白了。已经取消删除并添加了一张图片。 - guyabel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接