0
votes

I've created an interactive plotly chart with plotly() in R and I'd like to save it as a file.

I'm okay with it being in any format, whether that's js or html or something else. I want to keep the interactivity.

This is my code

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

ggplotly(gg)

I read on this answer that you can do plotly.offline.plot(data, filename='file.html') in the Python implementation for Plotly. My goal is to upload the plotly chart to a Notion document using the "upload file" functionality.

1

1 Answers

1
votes

You can try with saveWidget() from htmlwidgets package:

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")