title: shiny error Error in .getReactiveEnvironment()$currentContext() :
body: <p>What I basically intend to do is select a subset according to users' input and do some manipulation like computing the percentage of each dataset and draw a ggplot. But when I was writing the shiny app server it kept giving me error as:</p>
  
  <pre><code>Listening on http://127.0.0.1:5884
  Warning: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
  Stack trace (innermost first):
      48: .getReactiveEnvironment()$currentContext
      47: .subset2(x, "impl")$get
      46: $.reactivevalues
      45: $
      44: eval
      43: eval
      42: subset.data.frame
      41: subset
      40: server [/Users/Qiner/Downloads/ME Analyst Assessment Files/server.R#7]
       1: runApp
  Error in .getReactiveEnvironment()$currentContext() : 
    Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
  </code></pre>
  
  <p>I've tried the <code>reactive({})</code> function as suggested by existing answers but the error still goes on. Does anyone know the answer? Appreciate it so much! Here is my code:</p>
  
  <pre><code>    server &lt;- function(input, output) {
        library(shiny)
        library(radarchart)
        library(ggplot2)
        library(reshape2)
      top_version&lt;-read.csv("top_version.csv",header = T)
        #plot1 data
        ds&lt;-subset(top_version,top_version$ageInd==input$select1)
        labs&lt;-c('familiarity','favorability','consideration')
        scores&lt;-reactive({
        scores&lt;-list('Women'=c(nrow(ds[ds$familiarity==1 &amp; ds$gender==2,])/nrow(ds[ds$gender==2,]),nrow(ds[ds$favorability==1 &amp; ds$gender==2,])/nrow(ds[ds$gender==2,]),nrow(ds[ds$consideration==1 &amp; ds$gender==2,])/nrow(ds[ds$gender==2,])),
                     'Men'=c(nrow(ds[ds$familiarity==1 &amp; ds$gender==1,])/nrow(ds[ds$gender==1,]),nrow(ds[ds$favorability==1 &amp; ds$gender==1,])/nrow(ds[ds$gender==1,]),nrow(ds[ds$consideration==1 &amp; ds$gender==1,])/nrow(ds[ds$gender==1,])))
        })
         #plot2 data
        scores2&lt;-list("Age 18-24"=c(nrow(top_version[top_version$familiarity==1 &amp; top_version$ageInd=="Age 18-24",])/nrow(top_version[top_version$ageInd=="Age 18-24",]),nrow(top_version[top_version$favorability==1 &amp; top_version$ageInd=="Age 18-24",])/nrow(top_version[top_version$ageInd=="Age 18-24",]),nrow(top_version[top_version$consideration==1 &amp; top_version$ageInd=="Age 18-24",])/nrow(top_version[top_version$ageInd=="Age 18-24",])),
                      "Age 25-44"=c(nrow(top_version[top_version$familiarity==1 &amp; top_version$ageInd=="Age 25-44",])/nrow(top_version[top_version$ageInd=="Age 25-44",]),nrow(top_version[top_version$favorability==1 &amp; top_version$ageInd=="Age 25-44",])/nrow(top_version[top_version$ageInd=="Age 25-44",]),nrow(top_version[top_version$consideration==1 &amp; top_version$ageInd=="Age 25-44",])/nrow(top_version[top_version$ageInd=="Age 25-44",])),
                      "Age 45-64"=c(nrow(top_version[top_version$familiarity==1 &amp; top_version$ageInd=="Age 45-64",])/nrow(top_version[top_version$ageInd=="Age 45-64",]),nrow(top_version[top_version$favorability==1 &amp; top_version$ageInd=="Age 45-64",])/nrow(top_version[top_version$ageInd=="Age 45-64",]),nrow(top_version[top_version$consideration==1 &amp; top_version$ageInd=="Age 45-64",])/nrow(top_version[top_version$ageInd=="Age 45-64",])),
                      "Age 65+"=c(nrow(top_version[top_version$familiarity==1 &amp; top_version$ageInd=="Age 65+",])/nrow(top_version[top_version$ageInd=="Age 65+",]),nrow(top_version[top_version$favorability==1 &amp; top_version$ageInd=="Age 65+",])/nrow(top_version[top_version$ageInd=="Age 65+",]),nrow(top_version[top_version$consideration==1 &amp; top_version$ageInd=="Age 65+",])/nrow(top_version[top_version$ageInd=="Age 65+",])))
        #plot3 data
  com_1&lt;-subset(top_version,familiarity==as.integer(input$select2) &amp; favorability==as.integer(input$select3) &amp; as.integer(input$select4))
      com_2&lt;-subset(top_version,familiarity==as.integer(input$select5) &amp; favorability==as.integer(input$select6) &amp; as.integer(input$select7))
      abc_0&lt;-reactive({
        de_1&lt;-rep(nrow(com_1),19)
        sum_0&lt;-apply(com_1[,1:19],2,sum)
        portion_0&lt;-sum_0/de_1
        #return(portion_0)
      })
      abc_1&lt;-reactive({
        de_2&lt;-rep(nrow(com_2),19)
        sum_1&lt;-apply(com_2[,1:19],2,sum)
        portion_1&lt;-sum_1/de_1
        #return(portion_1)
      })
  
        df&lt;-reactive({
          df&lt;-melt(data.frame(i=names(top_version)[1:19],name1=abc_0(),name2=abc_1()),id="i")
        })
  
     #begin plot
        output$plot1 &lt;- renderPlot({
          chartJSRadar(scores=scores(), labs=labs,showToolTipLabel = T)
        })
        output$plot2 &lt;- renderPlot({
          chartJSRadar(scores=scores2, labs=labs,showToolTipLabel = T)
        })
        output$plot3 &lt;- renderPlot({
          ggplot(df(), aes(x=i,y=value,colour=variable,group=variable)) + 
            geom_line()+theme(axis.text.x = element_text(angle = 90, hjust = 1))
        })
  
      }
  </code></pre>