Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display PDF file which isn't stored on www folder inside R shiny app

Tags:

r

pdf

iframe

src

shiny

I would like to create pdf viewer in R shiny app for a PDF which isn't located on www folder.

In the following code, if my_path doesn't refers to www folder, it seem's to be not working.

library(shiny)

ui <- fluidPage(
  uiOutput("PDF_WINDOW")
)

server <- function(input, output, session) {
  output$PDF_WINDOW <- renderUI({
    tags$iframe(style="height:485px; width:100%", src= my_path)
  })
}

shinyApp(ui, server)

Thank's for any suggestion

like image 625
JeanBertin Avatar asked Aug 31 '25 21:08

JeanBertin


1 Answers

You need to make the folder containing the pdf file available to the webserver. This can be done via addResourcePath:

library(shiny)

my_path <- "/path/to/folder/containing/the/pdf/file"
addResourcePath(prefix = "my_pdf_resource", directoryPath = my_path)

ui <- fluidPage(
  uiOutput("PDF_WINDOW")
)

server <- function(input, output, session) {
  output$PDF_WINDOW <- renderUI({
    tags$iframe(style="height:50vh; width:100%", src = "my_pdf_resource/my_pdf_filename.pdf")
  })
}

shinyApp(ui, server)

As you can see, the defined prefix substitutes the path in the src argument.

like image 119
ismirsehregal Avatar answered Sep 04 '25 02:09

ismirsehregal