1
votes

I wanted to upload a file, change it in some way and then download it with some lines changed. The write() function can't be replaced for this code.

There it is my summarized code:

shinyServer(function(input, output) {
  inFile <- reactive({input$file})
  archive <- reactive({scan(inFile$datapath, what = character(), skip = 1, sep= "\n")})

  output$downloadData <- downloadHandler(
    filename = function() { 
      paste("something", '.cfg', sep='') 
    },
    content = function(file) {
      write(archive, file)
    }
  )
})

>

shinyUI(fluidPage(
        fileInput("file", label="Something: "),
        downloadButton('downloadData', 'Download')
))

It throws me an error when I try to dowload the file I just uploaded:

Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'closure') not handled by 'cat'

Thank you

edit: I tried omitting the reactive() function when assigning it to "archive", but it tells me that inFile$datapath : object type "closure" is not a subset, and I also tried assigning "as.character(reactive(scan ...))" to archive but it doesnt work.

1

1 Answers

0
votes

Realized there were 2 problems:

  1. "inFile" and "archive" vars had to be inside an "observe({})" statement.
  2. In order to ve visible to the downloadHandler, archive must be assigned with the "<<-" operator, not "<-", in order to be a global var.