Adding text/values to the Notes view in PowerPoint from a shiny app

Hello!

I am using Shiny to build a PowerPoint presentation.

Is there a way to add notes in the "Notes View" from Shiny, please?

Thanks,
Erin

Hi Erin!

If I interpret correctly, you are looking for a way to send the values from a Shiny input (e.g. a textInput) to the "notes" section of a PPT slide. Though it's not specified in your question, I assume you are using {officer} to do this.

If that's the case, I think the following example app might be useful:

library(shiny)
library(officer)
library(dplyr)
  
ui <- fluidPage(
  column(
    width = 12,
    textInput(
      "note_text",
      label = "Input text for note",
      value = "..."
    ),
    downloadButton("download_powerpoint", "Download PowerPoint")
  )
)
    
server <- function(input, output) {
  output$download_powerpoint <- downloadHandler(
    filename = function() {
      "example.pptx"
    },
    content = function(file) {
      read_pptx() %>%
        add_slide(layout = "Title Slide", master = "Office Theme") %>%
        ph_with(
          value = "Presentation Title",
          location = ph_location_type(type = "ctrTitle")
        ) %>%
        ph_with(
          value = "Some subtitle",
          location = ph_location_type(type = "subTitle")
        ) %>%
        add_slide(layout = "Title and Content", master = "Office Theme") %>%
        ph_with(
          value = "Some title",
          location = ph_location_type(type = "title")
        ) %>%
        # This is the function that might come in handy for your case.
        set_notes(
          value = input$note_text,
          location = notes_location_type("body")
        ) %>%
        print(target = file)
    }
  )
}
      
shinyApp(ui, server)

This app will take whatever text you input in the textInputand set that as the "notes" text in the 2nd slide of the output ppt (to render this ppt, just click on the "Download PowerPoint" button).

The key function here is officer::set_notes*
*Note, I the latest release version of the pkg, which might be relevant if you are using an older version, since some functions have changed along development).

Hope this helps :slight_smile:
Cheers!


This post was published by an Appsilon team member. Our company can help you get the most out of RShiny and Posit/RStudio products.

Check our open positions here.

Appsilon: Building impactful RShiny Dashboards and providing R coding services.
Appsilon_GIFsmall_whitebg

1 Like

Awesome!

Thank you so much!
Sincerely,

Erin

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.