title: R Shiny & htmltools - Extracting a tag by name
body: <p>I have a <code>tagList</code> of two Shiny inputs, <code>inputs</code>. I would like to extract the <code>label</code> tag for each input. I was hoping that <code>htmltools</code> had a getter function to achieve this but in the absence of one I've defined a function, <code>getLabel</code>, that recurses through the input list and extracts the sublists whose name element equals the value <code>label</code>. Here is my code: </p>
  
  <pre><code>library(htmltools)
  library(shiny)
  
  inputs = tagList(
      selectInput('first', 'FIRST', letters), 
      checkboxInput(inputId = 'second', label = 'SECOND')
  )
  
  getLabel2 &lt;- function(children) {
  
    lapply(children, function(x) {
  
      if(inherits(x, 'shiny.tag')) {
  
        if(x$name == 'label') {
  
          return(x)
  
        } else {
  
          chldn = x$children
  
          if(is.list(chldn)) getLabel2(chldn)
  
        }
  
      }
  
    })
  
  }
  
  
  getLabel &lt;- function(inputs) {
  
    lapply(inputs, function(x) {
  
      if(grepl('shiny-input-container', tagGetAttribute(x, 'class'))) {
  
        getLabel2(x$children)
  
      } else {
  
        return(x)
  
      }
  
    })
  }
  
  labels = getLabel(inputs)
  </code></pre>
  
  <p>The problem is that the resulting list includes zero-length sublists. My desired output is a list of two elements (the label for each input) of class 'shiny-tag'. How can I modify my function to achieve this? Also, can this be done in <code>htmltools</code>? I can't find any relevant getters in the package manual.</p>