1

In my below example of a simple shiny app i recently created, im currently trying to include also the possibility of downloading a data frame that is created from the results. I mention here part of the server.R script in order to not make a huge post:

 shinyServer(function(input, output) {

 table_options<- list(lengthMenu = list(c(5,10,15,20),
 c('5','10', '15', '20')), pageLength = 15, ordering=TRUE,
 class = 'cell-border stripe',dom ='t',scrollX = TRUE,
 fixedColumns = list(leftColumns = 2, rightColumns = 1))


 inTable <- reactive({# upload a tsv file
 inFile <- input$file1

 if (is.null(inFile))
 return(NULL)

 read.table(inFile$datapath,header=input$header, 
 sep="\t",stringsAsFactors = FALSE)

 }) #END REACTIVE

 rv <- reactiveValues()
 rv$data <- NULL # to further use it into the observeEvent below

 observeEvent(input$goButton, {

 df <- inTable()
 # some data manipulation with df...

 if(input$repo_option=="mimic"){

 # some functions here that result to a data frame named final dat
 rv$data <- final.dat
 rv$data
 }

 else if(input$repo_option=="reverse"){

 # similar procedure...
 rv$data <- final.dat
 rv$data
 }
 })

 output$contents <- DT::renderDataTable({
    expr=DT::datatable(rv$data, options=table_options,
    extensions ='FixedColumns',selection="none")
    })

  output$downloadData <- downloadHandler(
      filename = function() { paste("input$file1", ".csv", sep=",") },
    content = function(file) {
      write.csv(rv$data,file)
    }
  )    


  })

My main issue is that, although the output$contents works fine in the app, when i press the download button from the ui.R server (not posted here for simplicity), the download "pop-up" window appears, but the saving does not work. Thus, i suspect that is something wrong with the code in the downloadHandler function, but any ideas or help ?

Jason
  • 203
  • 1
  • 11
  • This won't solve your issue but : `paste(input$file1, ".csv", sep=",")` – HubertL Dec 27 '16 at 01:17
  • also replace the last `else if` with `else` to ensure all routes assign `rv$data` – HubertL Dec 27 '16 at 01:20
  • Dear HubertL, thank you for your answer-regarding the paste function, i changed it but it did not solve this issue (as you have already mentioned)-regarding the second part with ifelse: because in the ui.R script i have the function radioButtons that is related to these two options (mimic and reverse), that's why i used else if. – Jason Dec 27 '16 at 01:32
  • View your app in a browser, not from RStudio's viewer, if you're using that. http://stackoverflow.com/questions/25984138/shiny-app-downloadhandler-does-not-produce-a-file?rq=1 – Jean Dec 27 '16 at 02:26
  • Thank you waterling for your helpful comment and relative previous post. I opened the Browser and then the download button worked. – Jason Dec 27 '16 at 13:39

0 Answers0