title: Error in if: argument is of length zero: encountered in a shiny app after trying to refer to an reactive element twice
body: <p>I'm completely new to R and shiny apps and couldn't find a solution for this specific problem:
  I tried to realize a shiny app that allows users to upload their own data file and do further analysis with the columns of the specific data file. Computing Cohen's D and the t-test works just fine. Only the effect size of Cohen's D seems to be problematic.
  I really don't get what I'm doing wrong/missing. Maybe it's because I'm referring to the reactive element &quot;linking&quot; twice or in the wrong order, I really don't know.</p>
  <p>The entire code:</p>
  <pre><code>library(shiny)
  library(effectsize)
  shinyApp(
    ui = fluidPage(
      div(id = &quot;myapp&quot;,
          h2(&quot;Upload my own data&quot;),
          fileInput(&quot;example&quot;, &quot;&quot;,
                    accept= c(&quot;csv&quot;)),
          actionButton(&quot;load&quot;, &quot;Upload data&quot;), 
          conditionalPanel(                    
            condition = &quot;input.load &gt;= '1'&quot;,   
            uiOutput(&quot;var1&quot;),                 
            uiOutput(&quot;var2&quot;)),
          h2(&quot;Compute Cohen's D&quot;),
          actionButton(&quot;selectD&quot;, &quot;Show&quot;),
          conditionalPanel(                    
            condition = &quot;input.selectD &gt;= '1'&quot;,   
            uiOutput(&quot;cohensd&quot;)),
          h2(&quot;Effect Size Cohen's D&quot;),
          actionButton(&quot;selectDEf&quot;, &quot;Show&quot;),
          conditionalPanel(                    
            condition = &quot;input.selectDEf &gt;= '1'&quot;,   
            uiOutput(&quot;cohensdEsize&quot;)),
          h2(&quot;Compute t-test&quot;), 
          actionButton(&quot;select&quot;, &quot;Show&quot;),
          conditionalPanel(                    
            condition = &quot;input.select &gt;= '1'&quot;,    
            uiOutput(&quot;t.test&quot;))
      ),
      mainPanel(
        verbatimTextOutput(&quot;cohen&quot;)
      )
    ),
    server = function(input, output) {
      values &lt;- reactiveValues()
      dataInput &lt;- reactive({
        data &lt;- read.csv(input$example$datapath)
      }
      )
      output$var1 &lt;- renderUI({    # remember variable 1? here it is how we extract it
        nam &lt;- colnames(values$data) # from the data set
        selectInput(&quot;var1&quot;, label = &quot;Select group 1:&quot;, # create the input
                    choices = c(nam), multiple = FALSE,
                    selected = nam[1])
      })
      
      output$var2 &lt;- renderUI({
        nam2 &lt;- colnames(values$data) # create the input for variable 2
        selectInput(&quot;var2&quot;, label = &quot;Select group 2:&quot;,
                    choices = c(nam2), multiple = FALSE,
                    selected = nam2[1])
      })
      observeEvent(input$load, {
        values$data &lt;- data.frame(dataInput())
      })
      output$t.test = renderPrint({
        t &lt;- t.test(values$data[,input$var1],values$data[,input$var2])
        cat(&quot;t-statistic:&quot;, t$statistic, &quot;| degrees of freedom:&quot;, t$parameter, &quot;| p-value:&quot;, t$p.value)
      })
      linking &lt;- reactive({
        mean1 &lt;- mean(values$data[,input$var1])
        mean2 &lt;- mean(values$data[,input$var2])
        sd1 &lt;- sd(values$data[,input$var1])
        sd2 &lt;- sd(values$data[,input$var2])
        n1 &lt;- length(values$data[,input$var1])
        n2 &lt;- length(values$data[,input$var2])
        cat((mean1 - mean2)/
              (sqrt((n1 - 1)*(sd1^2) + (n2 - 1)*(sd2*2)) / (n1 + n2 - 2)))
      })
      output$cohensd = renderPrint(linking())
      output$cohensdEsize = renderPrint({linking()*4
      })
    })
  </code></pre>
  <p>The error: Error in if: argument is of length zero
  I don't get why linking() should be empty
  If somebody could help me, I would be very thankful!</p>