I have used this answer to embed a pdf in my shiny app. When I first generate the pdf through shiny UI inputs and "submit" with an action button the pdf is generated from the UI inputs and displays in the Viewer fine.
However when I change the document through the UI and and submit again the viewer still displays the old report even though the file contents have changed.
How can I force it to display the new pdf?
This is reproducible example of my problem, works best when opened in browser.
ui.R
library(shiny)
shinyUI(fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
textInput("textin", label = "text input")
, actionButton("makepdf", "Make pdf")
),
mainPanel(
htmlOutput("pdfviewer")
)
)
))
server.R
library(shiny)
shinyServer(function(input, output) {
observeEvent(input$makepdf,{
title <- input$textin
print(title)
pdf("www/test.pdf")
plot(mtcars$mpg,mtcars$disp, main = title)
dev.off()
})
observeEvent(input$makepdf,({
output$pdfviewer <-renderText({
return(paste('<iframe style="height:600px; width:100%" src="'," test.pdf", '"></iframe>', sep = ""))
})
})
)
})
Steps to reporoduce:
- Launch app in browser
- Type anything in the "text input" box and click "Make pdf"
- Type something different in the "text input" box and click "Make pdf"
- Observe the pdf viewer still shows output from step 2 even though the source file in your www folder will display the change made in step 3.