0

My Shiny app contains a DT table with single selection enabled as well as the rowGroup extension to separate my data into the different categories. When the user clicks on a row of the table, a plot is updated to reflect the row's data. However, it seems like the rowGroup extension create a new row in the table, making it selectable. As there is no data in group rows, the plot throws an error. I also need collapsible rows, and as the user will need to click on the group row to make it collapse, it creates again the issue of selected group rows.

I came across this solution when I looked for ways to make the group rows collapsible. To make them non-selectable as well as collapsible, I tried to add no-select('true') to the group row callback but this did not work.

Is there any way to make group rows non selectable?

Reproductible example:

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');
        var groupRows = $(this);
        $(groupRows).no-select('true');
    });
    "

)

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 = 'single'
        )
    })
}

# Run the application
shinyApp(ui = ui, server = server)
yben
  • 1
  • 1

0 Answers0