Hi,
I have been trying to resolve this issue for a while now. I have several drop-down lists and a download button. One of the drop-down lists selects between two reports. One of them is a HTML report and the other is pdf.
This is how I handled the downloadhandler for the download button:
(part of the server.R code)
reportname <- reactive({
reportname<- paste0(input$selectreport,".Rmd")
})
ending <- reactive({
if (input$selectreport =="Report1") ending<-".html"
else{ending <-".pdf"}
})
parameters <- reactive({
if (input$selectreport =="report1") {
list(n = input$file1$datapath,
obs=input$obs)}else{
list(n = input$file1$datapath,
variable=input$inSelect)}
})
filename <- reactive({
filename<-paste0(input$selectreport , ending())
})
observe({
print(filename())
})
output$report <- downloadHandler(
filename =filename(),
content = function(file) {
tempReport <- file.path(tempdir(), reportname())
file.copy(reportname(), tempReport, overwrite = TRUE)
params <- parameters()
waitress$start()
rmarkdown::render(tempReport, output_file = file,
params = params,
envir = new.env(parent = globalenv())
)
waitress$close() # hide when done
}
)
While the download works fine and the document generated is the right document, the name is always set as report1.html.
No matter what I do the file ending will always be .HTML unless I change the filename() to "report2.pdf".
I use observe to confirm that the filename() contains "report2.pdf" and yet when I download the report I receive "report1.html" every time.
I would be grateful for any guidance on how to fix the issue or how to use a different approach to switch between pdf. and HTML reports being downloaded from two different r markdown documents.