0

I've successfully added RowGroups to a DT datatable in Shiny (thanks to this). Expanding on this, I want to get the clicked RowGroup instead of the usual clicked row:

library(shiny)
library(DT)
ui <- fluidPage(# Application title
  titlePanel("Collapse/Expand table"),
  mainPanel(DTOutput("my_table")))

callback_js <- JS(
  "table.on('click', 'tr.dtrg-group', function () {",
  "  var rowsCollapse = $(this).nextUntil('.dtrg-group');",
  "  $(rowsCollapse).toggleClass('hidden');",
  "});"
)

server <- function(input, output) {
  output$my_table <- DT::renderDT({
    datatable(
      mtcars[1:15, 1:5],
      extensions = 'RowGroup',
      options = list(rowGroup = list(dataSrc = 3), pageLength = 20),
      callback = callback_js,
      selection = 'none'
    )
  })

  # Typical row-based selection 
  observe({
    print(input$my_table_rows_selected)
  })
  
  # Here is what I want to do
  observe({
    print(input$my_table_row_groups_selected) # something like this...
  })
}

# Run the application
shinyApp(ui = ui, server = server)

Will Hipson
  • 366
  • 2
  • 9

0 Answers0