1

I have been working on a shiny app that will allow users to pick a pdf from a file directory that is in the app and display it on screen using an iframe by letting users first select the folder that holds the pdfs, and then select a specific pdf inside of that folder. However, the way I have it setup now will not display the pdf on the screen, it instead shows a not found error in the iframe.

Here is my code:

library(shiny)

ui <- fluidPage(

  headerPanel("Client"),

  selectInput("folder", "Select the report type", 
              c(dir("Reports/"))),

  conditionalPanel(
    condition = "input.folder == 'Invoice Analysis'",
    selectInput("report", "Choose the PDF",
                          choices = dir("Reports/Invoice Analysis"))),

  conditionalPanel(
    condition = "input.folder == 'Pole Attachments'",
    selectInput("report", "Choose the PDF",
                          choices = dir("Reports/Pole Attachments"))),

  htmlOutput("pdfviewer")

)

server <- function(input, output){

  output$pdfviewer <- renderUI({
    tags$iframe(src=(input$report), height=300, width=600)
  })

}

shinyApp(ui = ui, server = server)

Here is the current output:

App Output

I can replace the src in the iframe with a website and it displays the site correctly.

example:

tags$iframe(src=("http://www.w3schools.com"), height=300, width=600)

This leads me to believe that somehow I am getting this section of my code wrong. I have also tried something like this:

tags$iframe(src=(paste0(input$folder, input$report), height=300, width=600)

but it gives me the same not found error. Can anyone think of a way to make the source of the iframe a selection from the user? I am very new at r and shinyapps so I don't know if this is a syntax problem, or if I am going about this the wrong way. Thank you in advance for the help.

Dustin Knight
  • 350
  • 1
  • 4
  • 17
  • did u try to put them into the "www" folder and/or check with `file.exists()` whether the files are correctly linked from within R/Shiny? – Tonio Liebrand Mar 06 '17 at 15:47
  • What exactly is the "www" folder? What is it used for? I have seen people mention it on other questions but I don't already have this folder. Should I create a folder and call it "www"? – Dustin Knight Mar 06 '17 at 15:58
  • that is the folder where shiny "looks for" files,...(it is within the same folder where your app.R or server/ui.R is) What is your output of `file.exists()`? If your files can not be found try `addResourcePath()`. – Tonio Liebrand Mar 06 '17 at 16:53
  • I added `file.exists(paste0( "Reports/", input$folder, "/", input$report))` and it returned TRUE. However, when I try to use this path as a source like this: `tags$iframe(src=(paste0("Reports/", input$folder, "/", input$report)), height=300, width=600)` I'm now getting an error that says ERROR: argument 1 (type 'list) cannot be handled by 'cat'. Any ideas for how to get around it? – Dustin Knight Mar 06 '17 at 19:37
  • well then it is not the path but the displaying and then you this should help: http://stackoverflow.com/questions/19469978/displaying-a-pdf-from-a-local-drive-in-shiny – Tonio Liebrand Mar 06 '17 at 20:31

0 Answers0