title: How to fix 'File not found' when using the downloadHandler?
body: <p>I just started to play around in shiny and made a simple app that reads a CSV file and replaces rows of one column with tokens. I would like the user to be able to download the tokenized data as a CSV file. </p>
  
  <p>To do this I am using the <code>downloadHandler()</code> function. I have been looking in the documentation for this function, as well as similar questions in here but haven't been able to find a solution. I tried running the app externally as suggested in other similar questions. </p>
  
  <p>app.R</p>
  
  <pre class="lang-r prettyprint-override"><code># Only run examples in interactive R sessions
  if (interactive()) {
  
    ui &lt;- fluidPage(
      sidebarLayout(
        sidebarPanel(
          fileInput("file1", "Choose CSV File",
                    accept = c(
                      "text/csv",
                      "text/comma-separated-values,text/plain",
                      ".csv")
          ),
          tags$hr(),
          checkboxInput("header", "Header", TRUE),
          textInput(inputId = 'variable', label = 'Name of variable to pseudonymize', placeholder = 'e.g., ID_PA'),
          helpText("Case sensitive!"),
          downloadButton('downloadData', 'Download')
        ),
        mainPanel(
          tableOutput("contents"),
          br(), br(),
          tableOutput('results')
        )
      )
    )
  
    server &lt;- function(input, output) {
      output$contents &lt;- renderTable({
        # input$file1 will be NULL initially. After the user selects
        # and uploads a file, it will be a data frame with 'name',
        # 'size', 'type', and 'datapath' columns. The 'datapath'
        # column will contain the local filenames where the data can
        # be found.
        inFile &lt;- input$file1
  
        if (is.null(inFile))
          return(NULL)
  
        head(read.csv(inFile$datapath, header = input$header))
  
      })
  
      output$results &lt;- renderTable({
        # input$file1 will be NULL initially. After the user selects
        # and uploads a file, it will be a data frame with 'name',
        # 'size', 'type', and 'datapath' columns. The 'datapath'
        # column will contain the local filenames where the data can
        # be found.
        inFile &lt;- input$file1
  
        if (is.null(inFile))
          return(NULL)
  
        df &lt;- read.csv(inFile$datapath)
  
        # make sure to use utils::read_csv to read in data
  
        #  Function generates a lookup table that associates each unique identifier to an PSN. See lillemets
        get_lookup_table &lt;- function(data, id.var, key.length) {
          if (any(duplicated(data[, id.var]))) warning('Duplicate id values in data. For longitudinal dataset, this is expected')
          PSN &lt;- c(1,1) # Allow the while loop to begin
          while (any(duplicated(PSN))) { # Loop until all keys are unique
            PSN &lt;- replicate(length(unique(data[, id.var])),
                             paste(sample(c(LETTERS, 0:9), key.length, replace = T), collapse = ''))
          }
          lookup.table &lt;- data.frame(id = unique(data[, id.var]), key = PSN)
          return(lookup.table)
        }
  
        # Replace names with PSN
        add_PSN &lt;- function(data, id.var, lookup.table) {
          data[, id.var] &lt;- lookup.table[, 'key'][match(data[, id.var], lookup.table[, 'id'])]
          return(data)
        }
  
        lookup_table &lt;- get_lookup_table(df, input$variable, 10)
  
        # Replace names with PSN
        pseudo_df &lt;- add_PSN(df, input$variable, lookup_table)
        head(pseudo_df)
  
  
      })
  
  
      # Download file
      output$downloadData &lt;- downloadHandler(
        filename = function() {
          paste("data-", Sys.Date(), ".csv", sep="")
        },
        content = function(file) {
          write.csv(pseudo_df, file)
        }
      )
    }
  
    shinyApp(ui, server)
  }
  </code></pre>
  
  <p>When running the app and clicking download, I get the browser error 'File not found'. 
  In the R console I get the warning: <code>Error in is.data.frame: object 'pseudo_df' not found</code></p>
  
  <p>Comments on this issue would be much appreciated. </p>