2

I have a PDF file that is constantly being updated and overwritten. It is saved in the www directory of the Shiny working directory. The problem is that the changes aren't being displayed in the app. The app still displays the first version of the pdf.

I originally had everything in the UI. I used tags$iframe in the ui.r code with the src pointing directly to the pdf file in the www directory.

Then I noticed that the pdf wasn't updating, so I tried to make an action button that when pushed would run the tags$iframe and display the pdf. This did not solve the problem. The updates in the pdf file are still not being displayed.

First attempt with everything in the UI


ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      h3("Title")
    ), 
    mainPanel(
      tabsetPanel(
        tabPanel("Tab 1", 
                 tags$iframe(style="height:1200px; width:100%; scrolling=yes", 
                  src="PDF1.pdf"))

      )
    )
 )

)


server <- function(input, output,session){

    }

shinyApp(ui, server)

Second attempt with the action button

library(shiny)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      h3("Title")
    ), 
    mainPanel(
      tabsetPanel(
        tabPanel("Tab1", 
                 sidebarLayout(
                    sidebarPanel(
                        actionButton("refresh_1", "Refresh PDF")
                    ),
                    mainPanel( 
                        uiOutput("Show_PDF1")
                    )
                )
        )

      )
    ))
)



server <- function(input, output,session){
  observeEvent(input$refresh_1, {
    output$Show_PDF1 <- renderUI({
        tags$iframe(style="height:1200px; width:100%; scrolling=yes", src="PDF1.pdf")
    })
  })  

}

shinyApp(ui, server)

I am hosting the app on a non pro version of shiny server, and accessing it with chrome. To recreate the problem you can put any pdf file into the /srv/shiny-server/www directory with the name PDF1.pdf, and access the app. Then overwrite PDF1.pdf with another pdf file and run the app again. You will see that the app is still displaying the original PDF1.pdf file.

javery1289
  • 67
  • 7
  • Please see [here](https://stackoverflow.com/questions/48343080/how-to-convert-a-shiny-app-consisting-of-multiple-files-into-an-easily-shareable/48343110#48343110) for guidance to improve your question. – Axeman Jul 08 '19 at 22:46
  • 1
    maybe with `reactiveFileReader` – Stéphane Laurent Jul 09 '19 at 19:31
  • @StéphaneLaurent thanks for the suggestion. I ended up adding a time flag to the pdf, and pointing the action button to a variable costa that matches any pdf file that begins with cr like this: ```costa <- list.files(path="/srv/shiny-server/www",pattern="^cr.*\\.pdf$")``` Now the pdf is changing when I hit the refresh button. I still don't understand why this step was necessary though. – javery1289 Jul 10 '19 at 02:02
  • @Axeman Thank you for the guidance. I simplified the code, and combined the ui and server so the app is easier to run. I have figured out a workaround to the problem, but if you have any ideas on why my original solutions weren't working I would be interested in hearing it. – javery1289 Jul 10 '19 at 03:06

0 Answers0