【问题标题】:How do I save an interactive plotly chart as a local file in R?如何将交互式绘图图表保存为 R 中的本地文件?
【发布时间】:2020-10-12 13:57:05
【问题描述】:

我在 R 中使用 plotly() 创建了一个交互式绘图图表,我想将其保存为文件。

我可以接受任何格式,无论是 js 还是 html 或其他格式。我想保持交互性。

这是我的代码

gg <-
   iris %>%
   ggplot(aes(Species, Sepal.length)) +
   geom_col(fill = "green")

ggplotly(gg)

我在this answer 上读到,您可以在 Plotly 的 Python 实现中执行 plotly.offline.plot(data, filename='file.html')。我的目标是使用“上传文件”功能将绘图图表上传到 Notion 文档。

【问题讨论】:

    标签: python r ggplot2 plotly


    【解决方案1】:

    您可以尝试使用来自htmlwidgets 包的saveWidget()

    library(plotly)
    library(tidyverse)
    library(htmlwidgets)
    #Plot
    gg <-
      iris %>%
      ggplot(aes(Species, Sepal.Length)) +
      geom_col(fill = "green")
    #Export
    saveWidget(ggplotly(gg), file = "myplot.html")
    

    【讨论】:

      猜你喜欢
      • 2022-07-06
      • 2017-10-03
      • 2018-10-25
      • 2021-06-16
      • 2021-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-24
      相关资源
      最近更新 更多