John Smith John Smith - 1 year ago 226
R Question

Shiny Download an excel file

I have a

server set up on a Linux instance
I have a folder called templates which has a excel file template
The user goes to the web page and presses a download button and in theory they should be able to download the template wherever they like on their local machine.

I have seen the code from the post Shiny download file not working

When i try and run it i get a file saved to
my downloads
on my windows laptop and it is called NA not the name Template.xlsx

My two questions are

  • Is it possible to prompt the user where to save the file locally

  • Is it possible to make it default to an

The pseudo code is

ui <- shinyUI(fluidPage(

# Side Panel with Options
column(4, wellPanel(
id = "leftPanel",
id = "Header",
h4("1. Download the empty excel template"),
downloadButton("downloadBtn", "Download Excel Template")


# Define server logic required
server <- shinyServer(
function(input, output) {

output$downloadBtn <- downloadHandler(
filename = function() {
paste(input$filenames, sep='')
content = function(file) {
myfile <- srcpath <- '/home/foo/Save to Database/templates/Template.xlsm'
file.copy(myfile, file)

Answer Source

You are using paste(input$filenames, sep='') but you don't have input$filenames defined in the UI part. It should work if you replace that line with "Template.xlsm"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download