title: Shiny app using lapply in server to generate renderUI but cant use an input to set the number
body: <p>I created a reproducible example below. I posted the first one which works however the ui formatting does not update the same amount as the comp_panel. This is because the lapply(1:5 function(i) { .. }) toward the end of server is set to 5, but instead I need it set to input$compnum like the renderUI panel above. My second post of code is what I tried but that fails. How can I make the last lapply function use an input value?</p>
  
  <p><strong>Working example but doesnt update properly.</strong></p>
  
  <pre><code>library(shiny)
  library(shinythemes)
  ui &lt;- fluidPage(navbarPage("Test",
  
                             tabPanel("Setup",
                                      fluidRow(align = "center",
                                               selectInput("compnum", NULL, choices = c(seq(2,20,1)), selected = 5)
                                      ), 
                                      fluidRow(align = "center",
                                               uiOutput("comp_panel")
  
                                      )
                             )
  ))
  
  ## server.r
  server &lt;- function(input, output) {
  
    # define component select panel for ui
    output$comp_panel &lt;- renderUI({ 
      lapply(1:input$compnum, function(i) {
        column(5,
               radioButtons(paste(paste("c",i,sep=""),"ac",sep=""), "AC:",
                            c("a" = "A",
                              "b" = "B",
                              "c" = "C",
                              "d" = "D"), inline = TRUE),
               radioButtons(paste(paste("c",i,sep=""),"style",sep=""), "Style",
                            c("a1" = "A1",
                              "b1" = "B1",
                              "c1" = "C1",
                              "d1" = "D1",
                              "e1" = "E1",
                              "f1" = "F1"), inline = TRUE),
               uiOutput(paste(paste("c",i,sep=""),"select",sep="")),
  
               br()
        )
      })
    })
  
    cnum &lt;- reactive ({
      input$comp_num
    })
  
    lapply(1:5, function(i) {
      output[[paste(paste("c",i,sep=""),"select",sep="")]] &lt;- renderUI({
        assign(paste("comp",i,sep=""), tryCatch(setNames("test1","Test1"),
                                                error = function(e) setNames("none","None Found")))
        selectInput(paste(paste("c",i,sep=""),"ticker",sep=""), paste("Component",i,sep=" "), get(paste("comp",i,sep="")))
      })
    })
  
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p><strong>Not working example (tried to make the 1:5 go to 1:input$compnum</strong></p>
  
  <pre><code>library(shiny)
  library(shinythemes)
  
  
  
  ui &lt;- fluidPage(navbarPage("Test",
  
                             tabPanel("Setup",
                                      fluidRow(align = "center",
                                               selectInput("compnum", NULL, choices = c(seq(2,20,1)), selected = 5)
                                      ), 
                                      fluidRow(align = "center",
                                               uiOutput("comp_panel")
  
                                      )
                             )
  ))
  
  ## server.r
  server &lt;- function(input, output) {
  
    # define component select panel for ui
    output$comp_panel &lt;- renderUI({ 
      lapply(1:input$compnum, function(i) {
        column(5,
               radioButtons(paste(paste("c",i,sep=""),"ac",sep=""), "AC:",
                            c("a" = "A",
                              "b" = "B",
                              "c" = "C",
                              "d" = "D"), inline = TRUE),
               radioButtons(paste(paste("c",i,sep=""),"style",sep=""), "Style",
                            c("a1" = "A1",
                              "b1" = "B1",
                              "c1" = "C1",
                              "d1" = "D1",
                              "e1" = "E1",
                              "f1" = "F1"), inline = TRUE),
               uiOutput(paste(paste("c",i,sep=""),"select",sep="")),
  
               br()
        )
      })
    })
  
    cnum &lt;- reactive ({
      input$comp_num
    })
  
    lapply(1:cnum(), function(i) {
      output[[paste(paste("c",i,sep=""),"select",sep="")]] &lt;- renderUI({
        assign(paste("comp",i,sep=""), tryCatch(setNames("test1","Test1"),
                                                error = function(e) setNames("none","None Found")))
        selectInput(paste(paste("c",i,sep=""),"ticker",sep=""), paste("Component",i,sep=" "), get(paste("comp",i,sep="")))
      })
    })
  
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>