title: Code for a reactive table to plot in Shiny
body: <p>I'm new to shiny, and I am trying to do a simple density plot where there are 2 groups of data, with reactive 'shifts' in the mean etc. 
  A simplified summary of this is that one set of data has a mean of 0, and variance of 1. The second set of data has a mean of <code>shift</code>, which is defined in a slider.</p>
  
  <p>I have tried to use <code>reactiveValues</code>, as shown in the code below to store the matrix of observations <code>d1</code>, generated from the <code>density</code> function y values,  and the corresponding x values are stored in  <code>x</code>. </p>
  
  <pre><code>
  library(shiny)
  
  # Define UI for application that draws a histogram
  ui &lt;- fluidPage(
  
     # Application title
     titlePanel("Old Faithful Geyser Data"),
  
     # Sidebar with a slider input for number of bins 
     sidebarLayout(
        sidebarPanel(
           sliderInput("shift",
                       "shift of 2nd set",
                       min = -1,
                       max = 1,
                       value = 0)
        ),
  
        # Show a plot of the generated distribution
        mainPanel(
           plotOutput("distPlot")
        )
     )
  )
  
  # Define server logic required to draw a histogram
  server &lt;- function(input, output) {
     data &lt;- reactiveValues({
  
       d1 &lt;- matrix(nrow=100, ncol=512)
       for(i in 1:70){
         d1[i,] &lt;- density(rnorm(1000),from = -3, to = 3)$y
       }
       for(i in 71:100){
         d1[i,] &lt;- density(rnorm(1000, input$shift),from = -3, to = 3)$y
       }
       x &lt;- density(rnorm(1000),from = -3, to = 3)$x
  
     })
     output$distPlot &lt;- renderPlot({
        matplot(data$x, t(data$d1), type = "l", lty = 1, col = c(rep(1,70),rep(2,30)))
     })
  }
  
  # Run the application 
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>The above code is largely from the example shiny app, so please excuse any generic references. It <em>should</em> still work.</p>
  
  <p>I was expecting a shiny plot with a slider on the left, and a plot on the right with 100 density lines in 2 colours. When the <code>shift</code> slider is changed the second set of data (red) will slide left or right depending on the shift.</p>
  
  <p>Instead, I get the error message</p>
  
  <pre><code>  55: stop
    54: .getReactiveEnvironment()$currentContext
    53: .subset2(x, "impl")$get
    52: $.reactivevalues
    47: server [/beavis/Documents/test/app.R#37]
  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>Is anyone able to help me fix this code? Any help will be greatly appreciated. Having played around for an hour I believe the issue lies in the <code>reactiveValues</code> section, but nothing so far has worked. </p>