title: Using length of checkboxGroupInput as an input for a loop to create multiple elements
body: <p>I'm creating Shiny app and I want to use checkboxGroupInput in order to print out multiple plots. However, I want to print out plots only for the elements of checkboxGroupInput that were checked. There is a similar <a href="http://shiny.rstudio.com/gallery/creating-a-ui-from-a-loop.html" rel="nofollow">example</a> in Shiny gallery to create UI elements in a loop that uses lapply. Here is a simplified version of that example to show what I want to do:</p>
  
  <pre><code>#server.R
  library(shiny)
  library(ggplot2)
  
  shinyServer(function(input, output, session) {
    numberInput &lt;- reactive({
      input$checkbox
    })
  
    lapply(1:10, function(i) {
      output[[paste0('b', i)]] &lt;- renderPlot({
        qplot(x = rnorm(100, mean = as.numeric(numberInput()[i]))) +
          ggtitle(paste("This plot was plotted with", numberInput()[i], "option"))
      })
    })
  })
  
  #ui.R
  library(shiny)    
  shinyUI(fluidPage(
    title = 'lapply example',
  
    sidebarLayout(
      sidebarPanel(
        checkboxGroupInput("checkbox", "Checkbox",
                           choices = sample(1:10, 5))
      ),
  
      mainPanel(
        lapply(1:10, function(i) {
          plotOutput(paste0('b', i))
        })
      )
    )
  ))
  </code></pre>
  
  <p>This works, but obviously when Shiny tries to extract <code>numberInput()[i]</code> where <code>i</code> is bigger than number of currently checked elements, there is nothing to extract and instead of a plot there is an error. Therefore I need to somehow tell <code>lapply</code> to iterate only <code>n</code> number of times where <code>n</code> is <code>length(input$checkbox)</code>.</p>
  
  <p>I tried to use <code>length(input$checkbox)</code> directly, tried putting that element in the <code>numberInput()</code> reactive statement and returning it as the list, I tried to use <code>reactiveValues()</code> in a following way:</p>
  
  <pre><code>  v &lt;- reactiveValues(n = length(input$checkbox))
  
    lapply(1:isolate(v$n), function(i) {
  </code></pre>
  
  <p>However, in all of those instances Shiny complains about lack of active reactive context.</p>
  
  <p>So, what am I missing? How can I use length of input in lapply outside of reactive context?</p>