title: Setting the focus to a numericInput within a modalDialog R/Shiny
body: <p>Within Shiny I'd like to be able to set the focus on the first field of a modalDialog which happens to be numericInput.</p>
  <p>In the example (which was based on the code from <a href="https://stackoverflow.com/questions/66218241/shiny-set-focus-to-input-in-modaldialog">Shiny: set focus to input in modalDialog</a> I can set the focus to the SelectInput but not the numericInput.  Any suggestions of a solution or where I may be able to find documentation that explains this would be appreciated.</p>
  <p>Thanks</p>
  <pre><code>library(shiny)
  
  ## create an event listener at &lt;body&gt; which fires as soon as the modal is shown
  ## sets the focus to the first text element (adapt if needed)
  jscode &lt;- HTML(&quot;$('body').on('shown.bs.modal', (x) =&gt; 
                     $(x.target).find('input[type=\&quot;text\&quot;]:first').focus())&quot;)
  
  # Define UI for application that draws a histogram
  ui &lt;- fluidPage(
    
    # Application title
    titlePanel(&quot;Old Faithful Geyser Data&quot;),
    tags$header(tags$script(type = &quot;text/javascript&quot;, jscode)),
    # Sidebar with a slider input for number of bins 
    sidebarLayout(
      sidebarPanel(
        sliderInput(&quot;bins&quot;,
                    &quot;Number of bins:&quot;,
                    min = 1,
                    max = 50,
                    value = 30),
        actionButton(&quot;show&quot;, &quot;Show Modal&quot;)
      ),
      
      # Show a plot of the generated distribution
      mainPanel(
        plotOutput(&quot;distPlot&quot;)
      )
    )
  )
  
  # Define server logic required to draw a histogram
  server &lt;- function(input, output) {
    
    output$distPlot &lt;- renderPlot({
      # generate bins based on input$bins from ui.R
      x    &lt;- faithful[, 2]
      bins &lt;- seq(min(x), max(x), length.out = input$bins + 1)
      
      # draw the histogram with the specified number of bins
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
    
    observeEvent(input$show, {
      showModal(ui = modalDialog(title = &quot;my modal dialog&quot;,
                                 numericInput(&quot;num_1&quot;, label = &quot;num 1&quot;, value = 1),
                                 selectInput(&quot;select_1&quot;, label = &quot;select 1&quot;, choices = c('1','2','3')),
                                 textInput(&quot;text_2&quot;, label = &quot;text 2&quot;)
      ))
    })
    
  }
  
  # Run the application 
  shinyApp(ui = ui, server = server)
  </code></pre>