codemob
codemob

Reputation: 51

Download handler does not save file shiny R

library(shiny)
library(plyr)

shinyServer(function(input, output){

  myfile<-reactive({
#reading 3 csv files and merging them into a dataframe
  })

  output$downloadData<-downloadHandler(

    filename = function(){

      paste("mergedfile","csv",sep='.')
    },

    content= function(file){
      write.csv(myfile(),file,sep=",")
    }
  )

})

I am reading 3-4 files reactively and then merging them. After that without displaying them I need to download the merged file.

I wrote the above code but a dialog box opens which asks me where to save but the file doesn't get saved. Am I doing something wrong with the download handler.

ui.R

downloadButton('downloadData','Download')

This is what I have in my main panel in ui.R file

Upvotes: 0

Views: 1635

Answers (1)

RmIu
RmIu

Reputation: 4487

Your probably using the Rstudio viewer to run the app? Open the app in your browser and your code will work ( click open in borwser or run runApp('/path/to/myApp',launch.browser=T) ).

See this link.

Also no need to set sep="," for write.csv since this is the default.

Upvotes: 2

Related Questions