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
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.