I would like to create a downloadButton
which downloads certain files. The problem I’m facing is that I can’t specify the destination path of the file in a Quarto dashboard. For that reason I’m trying to use file.copy
which copies the file to the right destination path. Here is a simple reproducible example:
---
title: "Test"
format: dashboard
server: shiny
---
```{r}
library(shiny)
```
```{r}
p("Choose a dataset to download.")
selectInput("dataset", "Dataset", choices = c("mtcars", "airquality"))
downloadButton("downloadData", "Download")
```
```{r}
#| context: server
# The requested dataset
data <- reactive({
get(input$dataset)
})
output$downloadData <- downloadHandler(
filename = function() {
# Use the selected dataset as the suggested file name
paste0(input$dataset, ".csv")
},
content = function(file) {
# Write the dataset to the `file` that will be downloaded
write.csv(data(), file)
file.copy(from = paste0("/Users/quinten/Downloads/", file),
to = paste0("/Users/quinten/", file))
}
)
```
Output:
The file always returns in my Downloads
folder which happens automatically so I tried to use file.copy
to copy the file to a different folder but that doesn’t work. So I was wondering if anyone knows how to use the file.copy
option in a downloadButton
module?
6