I have one PDF in the www directory of my shiny app. I would like that file to be available for download. How can i do that.
The download example works well, but no idea to use it for PDF download from www directory.
## Only run examples in interactive R sessions
if (interactive()) {
ui <- fluidPage(
downloadLink("downloadData", "Download")
)
server <- function(input, output) {
# Our dataset
data <- mtcars
output$downloadData <- downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".csv", sep="")
},
content = function(file) {
write.csv(data, file)
}
)
}
shinyApp(ui, server)
}
Open Acrobat and choose “Tools” > “Create PDF”. Select the file type you want to create a PDF from: single file, multiple files, scan, or other option. Click “Create” or “Next” depending on the file type. Follow the prompts to convert to PDF and save to your desired location.
You can also right-click the document and select Save as to save the PDF file. A window should appear, prompting you to specify the location where you'd like to save the file. Selecting the Desktop option makes it easy to find the PDF file later. If you like, you may rename the file at this point.
If the file is in the www
folder then you simply have to provide a link to it in the UI
... (in UI)
tags$a("Click here to get the PDF", href="your-pdf-name.pdf")
...
If the filename is not known at start time then use uiOutput/renderUI and set rv$filename to the filename when you generate it.
... (in UI)
uiOutput("dlURL")
...
... (in server)
rv <- reactiveValues(filename="")
output$dlURL <- renderUI({
tags$a("Click here to get the file", href=rv$filename)
})
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With