Shiny action button doesn't work inside modal dialog when filtering is enabled in DT::datatable

Viewed 623

In the example below, a table is displayed and the user clicks a button to open a modal dialog containing an input and an action button. When filtering is enabled in the table by setting filter = "top" in DT::datatable(), the action button in the modal dialog does not respond to clicks. If filter = "none" or if the table is hidden, the same action button does respond to clicks. Interestingly, if there is no input in the modal dialog, only the action button, the action button does respond to clicks.

I wonder if this is a bug in Shiny or DT or if there's a problem with my code. Any help figuring this out would be greatly appreciated.

Run the code below as-is to see the issue (submit button inside the modal dialog doesn't trigger a response). To make the submit button work as expected, you can do one of three things:

  1. comment out the output$myTable section and fluidRow(DTOutput("myTable"))
  2. set filter = "none" in DT::datatable().
  3. comment out the line selectInput("input1", ...)

I'm using DT version 0.17, Shiny version 1.6.0, and R version 4.0.4.

Update: With Shiny 1.5.0, the action button inside the modal dialog responded to clicks as expected. So it seems to be an issue with going from Shiny 1.5.0 to 1.6.0.

require(shiny)
require(DT)

shinyApp(
  ui = fluidPage(
    fluidRow(actionButton("myButton", label = "Click")),
    fluidRow(DTOutput("myTable"))
  ),
  server = function(input, output) {
    output$myTable <- renderDataTable({
      DT::datatable(
        data = mtcars[1:5, ],
        filter = "top"
      )
    })
    observeEvent(input$myButton, {
      showModal(modalDialog(
        selectInput("input1", label = "Input 1", choices = c("Ford F150", "Porsche 911")),
        actionButton("submit", label = "Submit")
      ))
    })    
    observeEvent(input$submit, {
      showModal(modalDialog(
        title = "Thank you",
        "You have clicked Submit."
      ))
    })    
  }
)
0 Answers
Related