title: r shiny: eventReactive is not reacting when the button is pressed
body: <p>Below is my code. It might seem a bit long but actually it's a VERY simple app.</p>
  
  <p>The user is supposed to upload a tiny data frame (x.csv if you are in the US or x_Europe.csv if you are in Europe). Then the user should click on the button to start calculations. And then at the end the user should be able to download the results of those calculations as a data frame.</p>
  
  <p>My problem: after I upload the file, when I click on the 'do_it' action button - nothing happens. I can see it because nothing is being printed to my console. WHY? After all, my function 'main_calc' should be eventReactive to input$do_it? Why do all the calculations inside main_calc start happening ONLY after the user tries to download the results?</p>
  
  <p>Important: It is important to me to keep the 'Data' function separately from main_calc.</p>
  
  <p>Thank you very much!</p>
  
  <p>First, generate one of these 2 files in your working directory:</p>
  
  <pre><code># generate file 'x.csv' to read in later in the app:
  write.csv(data.frame(a = 1:4, b = 2:5), "x.csv", row.names = F)  # US file
  write.csv2(data.frame(a = 1:4, b = 2:5), "x_Europe.csv", row.names = F)
  </code></pre>
  
  <p>This is the code for the shiny app:</p>
  
  <pre><code>library(shiny)
  
  ui &lt;- fluidPage(
    # User should upload file x here:
    fileInput("file_x", label = h5("Upload file 'x.csv'!")),
    br(),
    actionButton("do_it", "Click Here First:"),
    br(),
    br(),
    textInput("user_filename","Save your file as:", value = "My file x"),
    downloadButton('file_down',"Save the output File:")
  )
  
  server &lt;- function(input, output, session) {
  
    #----------------------------------------------------------------------
    # Function to read in either European (csv2) or American (csv) input:
    #----------------------------------------------------------------------
  
    ReadFile &lt;- function(pathtofile, withheader = TRUE){
  
      test &lt;- readLines(pathtofile, n = 1)  
      if (length(strsplit(test, split = ";")[[1]]) &gt; 1) {
        print("Reading European CSV file")
        outlist &lt;- list(myinput = read.csv2(pathtofile, header = TRUE),
                        europe.file = 1)
      } else {
        print("Reading US CSV file")
        outlist &lt;- list(myinput = read.csv(pathtofile, header = TRUE),
                        europe.file = 0)
      }
      return(outlist)
    }
  
    #----------------------------------------------------------------------
    # Data-related - getting the input file
    #----------------------------------------------------------------------  
  
    Data &lt;- reactive({
  
      print("Starting reactive function 'Data'")
      # Input file:
      infile_x &lt;- input$file_x
      myx &lt;- ReadFile(infile_x$datapath)$myinput
  
      # European file?
      europe &lt;- ReadFile(infile_x$datapath)$europe.file
  
      print("Finishing reactive function 'Data'")
      return(list(data = myx, europe = europe))
  
    })
  
    #----------------------------------------------------------------------
    # Main function that should read in the input and 'calculate' stuff
    # after the users clicks on the button 'do_it' - takes about 20 sec
    #----------------------------------------------------------------------
  
    main_calc &lt;- eventReactive(input$do_it, {
  
      req(input$file_x)
  
      # Reading in the input file:
      x &lt;- Data()$data
      print("Done reading in the data inside main_calc")
  
      # Running useless calculations - just to kill time:
  
      myvector &lt;- matrix(unlist(x), ncol = 1, nrow = 1000)
      print("Starting calculations")
  
      for (i in seq_len(10)) {
        set.seed(12)
        mymatr &lt;- matrix(abs(rnorm(1000000)), nrow = 1000)
        temp &lt;- solve(mymatr) %*% myvector
      }
  
      print("Finished calculations")
  
      # Creating a new file:
      y &lt;- temp
      result = list(x = x, y = y)
      print("End of eventReactive function main_calc.")
      return(result)
    })   # end of main_calc
  
    #----------------------------------------------------------------------
    # The user should be able to save the output of main_calc as a csv file
    # using a string s/he specified for the file name:
    #----------------------------------------------------------------------
  
    output$file_down &lt;- downloadHandler(
      filename = function() {
        paste0(input$user_filename, " ", Sys.Date(), ".csv") 
      },
      content = function(file) {
        print("Europe Flag is:")
        print(Data()$europe)
  
        if (Data()$europe == 1) {
          x_out &lt;- main_calc()$x
          print("Dimensions of x in downloadHandler are:")
          print(dim(x_out))        
          write.csv2(x_out, 
                     file,
                     row.names = FALSE)
        } else {
          x_out &lt;- main_calc()$x
          print("Dimensions of x in downloadHandler are:")
          print(dim(x_out))
          write.csv(x_out, 
                    file,
                    row.names = FALSE)
        }
      }
    )
  
  
  }  # end of server code  
  
  shinyApp(ui, server)
  </code></pre>