在没有互联网的情况下从 R 中的 Plotly 导出 PNG 文件互联网、情况下、文件、Plotly

2023-09-06 07:30:42 作者:呮潙沵變乖︶°

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

In this question, Exporting PNG files from Plotly in R I asked how to export Plotly plots to disk.

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

I used the function plotly_IMAGE, but later discovered that the function uses the Plotly internet servers.

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

The question is, now that Plotly JavaScript is local, how can I create a png local file without internet?

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

I tried this code, without success:

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

我们的想法是以编程方式进行,无需点击图表上方的导出按钮.

The idea is to make it programaticaly, without click on export button over the chart.

推荐答案

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

They've added a new export function to the plotly package. But to my knowledge it does the same thing as @MLavoie's answer suggests. Usage:

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