2

I have an RShiny application that generates a network plot using the diagrammeR package:

blc3001 <- eventReactive(input$datapath,{
    data_blc <- readxl::read_xlsx(input$datapath$datapath)
    blc3001 <- "digraph test{<TONS OF GRAPH CODE>"
})    

I can output to Shiny using:

output$blc3001 <- renderGrViz({
    grViz(blc3001())
  })

And I can download as a .png using:

  output$d_blc3001 <- downloadHandler(
    filename = "blc3001.png",
    content = function(file) {
      grViz(blc3001()) %>% export_svg %>% charToRaw %>% rsvg_png(file)
    },
    contentType = "image/png"
  )

Now I am trying to download this graph into a powerpoint slide, but am running into difficulty. I am open to any method or package, but I am currently trying to do this via the "officer" package.

output$blc3001_powerpoint <- downloadHandler(
    filename = function() {
      "blc3001.pptx"
    },
    content = function(file) {
      
      image <- grViz(blc3001()) %>% export_svg %>% charToRaw %>% rsvg_png()
                  
      ppt_report <- read_pptx() %>%
        add_slide(layout = "Title and Content", master = "Office Theme") %>%
        ph_with(value =  image, location = ph_location_type(type = "body"))

      print(ppt_report, target = file)
    }
  )

Although I can download the png, when I define ppt_report, I get error:

Error in UseMethod("ph_with", value) : 
  no applicable method for 'ph_with' applied to an object of class "raw"

I assume this is because I specify content type is img/PNG in the image download handler, but not the powerpoint download handler. I can download the powerpoint without error if I remove "%>% charToRaw %>% rsvg_png()" from defining image, but the powerpoint slide contains the XML code rather than rendering the actual svg. If anyone can please provide any tips on how to proceed I would greatly appreciate it! Thanks!

mbriganti
  • 21
  • 1

0 Answers0