【问题标题】:Exporting PNG files from Plotly in R without internet在没有互联网的情况下从 R 中的 Plotly 导出 PNG 文件
【发布时间】:2016-03-04 02:41:27
【问题描述】:

在这个问题中,Exporting PNG files from Plotly in R 我问如何将 Plotly 绘图导出到磁盘。

我使用了函数plotly_IMAGE,但后来发现该函数使用了 Plotly 互联网服务器。

问题是,既然 Plotly JavaScript 是本地的,我如何在没有互联网的情况下创建一个 png 本地文件?

我试过这段代码,没有成功:

library(plotly)
png(filename = "test.png")
plot_ly(x = 1:10)
dev.off()

这个想法是让它以编程方式进行,无需点击图表上方的导出按钮。

【问题讨论】:

    标签: r plotly r-plotly


    【解决方案1】:

    他们在plotly 包中添加了一个新的export 函数。但据我所知,它的作用与@MLavoie 的回答所暗示的相同。用法:

    p <- plot_ly(...)
    export(p, file = "test.png")
    

    【讨论】:

    • 现在已弃用
    【解决方案2】:

    您需要安装 Phantom (http://phantomjs.org/download.html),这很简单,您可以试试这个:

    library(plotly)
    library(webshot)
    library(htmlwidgets)
    
    m <- plot_ly(x = 1:10)
    saveWidget(as.widget(m), "temp.html")
    webshot("temp.html", file = "test.png",
            cliprect = "viewport")
    

    您将在您的工作目录中找到 temp.htmltemp.png

    【讨论】:

    • 我已经下载了phantomjs。但是当我运行上面的脚本时,我得到了以下错误:Error in find_phantom() : PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.你知道如何解决这个问题吗?
    • 你已经下载了,但是你安装了吗?
    • 我双击bin目录中的phantomjs文件,终端打开阅读:Last login: Mon May 30 10:47:54 on ttys001 /Users/Jonathan/Downloads/phantomjs-2.1.1-macosx/bin/phantomjs ; exit; JonathasMacBook:~ Jonathan$ /Users/Jonathan/Downloads/phantomjs-2.1.1-macosx/bin/phantomjs ; exit; phantomjs&gt;
    • 我使用的是 Mac,但我不记得有问题
    • 我不知道这是否重要,但我的笔记本电脑上确实有 macports。 phantoms 存储在 macports 下。
    猜你喜欢
    • 2016-03-01
    • 2012-05-18
    • 2013-10-16
    • 1970-01-01
    • 2010-11-24
    • 2017-03-15
    • 2015-05-24
    • 2013-09-11
    • 1970-01-01
    相关资源
    最近更新 更多