title: R shiny dynamic UI in insertUI
body: <p>I have a Shiny application where I would like to add a UI element using an action button and then have that inserted ui be dynamic. </p>
  
  <p>Here is my current ui file:</p>
  
  <pre><code>library(shiny)
  
  shinyUI(fluidPage(
    div(id="placeholder"),
    actionButton("addLine", "Add Line")
  ))
  </code></pre>
  
  <p>and server file:</p>
  
  <pre><code>library(shiny)
  
  shinyServer(function(input, output) {
    observeEvent(input$addLine, {
      num &lt;- input$addLine
      id &lt;- paste0("ind", num)
      insertUI(
        selector="#placeholder",
        where="beforeBegin",
        ui={
           fluidRow(column(3, selectInput(paste0("selected", id), label=NULL, choices=c("choice1", "choice2"))))
        })
    })
  
  })
  </code></pre>
  
  <p>If <code>choice1</code> is selected within the specific ui element, I would like to add a <code>textInput</code> to the row. If <code>choice2</code> is selected within the ui element, I would like to add a <code>numericInput</code>. </p>
  
  <p>While I generally understand how to create reactive values that change in response to user input, I don't know what to do here because I do not know how to observe an element that has not been created yet and that I do not know the name of. Any help would be very appreciated!</p>