0

I have a couple of plotly graphs in R that need to be exported to powerpoint, while retaining the interactivity. Is there a way to do this? I came across a solution for this that I am posting here. But the graph is just exporting as an image that does not have interactive features: https://community.rstudio.com/t/export-plotly-graphs-into-ms-powerpoint/33789/3

Does this code need to be tweaked in any way?

library(officer)
library(magrittr)
library(plotly)
library(htmlwidgets)
library(webshot)

temp_file_proc <- tempfile(pattern = "", fileext = ".png")
outout_file_proc <- here::here("presentation.pptx")

df <- mtcars
x <- plot_ly() %>% add_markers(data=mtcars, x=~wt, y=~disp)

saveWidget(x, "temp.html")
webshot("temp.html", temp_file_proc)

doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- ph_with(x = doc, value = "Title of the PPT", location = ph_location_type(type = "title"))
image_add <- external_img(temp_file_proc, width = 5, height = 5)
doc <- ph_with(x = doc, image_add,
               location = ph_location(left = 2.5, top = 2), use_loc_size = FALSE)

print(doc, target = outout_file_proc)
ACE
  • 311
  • 1
  • 2
  • 12
  • Pretty sure this isn't supported by officer, but I have seen other examples of people getting javascript running in powerpoint: https://stackoverflow.com/questions/67519747/output-of-plotly-in-powerpoint https://www.reddit.com/r/d3js/comments/qb3dr9/i_got_d3_to_work_in_powerpoints_relatively_new/ – Jon Spring Jun 01 '23 at 23:53

0 Answers0