You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue:
I'm using the row selection feature in reactable and setting selection = "single". The intention of this feature seems to function similarly to radio buttons. However, I'm finding that I can deselect the currently selected row, resulting in no rows selected at all.
Solution?
This behaviour seems counterintuitive for single selection mode, so I'm curious whether this is on purpose or indeed a bug?
Is it possible to add this feature (or perhaps a toggle) to ensure that a row must be selected at all times?
Hi, this is intentional, and honestly I've always felt that radio buttons not allowing deselection in general was odd. Maybe it differs based on whether there's a default selected value. Like if there must always be a selection, then yeah, deselection makes a lot less sense. But for most radio buttons where you start out with an unselected value, then I never understood why we couldn't deselect and return to the initial state, outside of refreshing the page to reset the form completely.
An option to disable deselection makes sense to me, and we'd just have to figure out the best way to put it in the API. For now, you can disable deselect on the Shiny server side, by watching for NULL selections and force-reselecting the previously selected row:
library(shiny)
library(reactable)
ui<- fluidPage(
reactableOutput("car_table")
)
server<-function(input, output) {
output$car_table<- renderReactable({
reactable(
mtcars,
selection="single",
onClick="select",
defaultSelected= c(1)
)
})
# You would use rv$selected to get the selected row, instead of getReactableState("car_table", "selected")rv<- reactiveValues(
selected=NULL
)
observe({
selected<- getReactableState("car_table", "selected")
if (!is.null(selected)) {
rv$selected<-selected
} else {
updateReactable("car_table", selected=rv$selected)
}
})
}
shinyApp(ui=ui, server=server)
Also worth noting is that other big data table libraries all support single row deselection by default, DataTables, ag-Grid, MUI. So it's not totally out of the ordinary to at least have this behavior by default.
Thanks @glin for the response, this seems very reasonable and appreciate your workaround solution! Yes, agreed having an option to disable deselect is probably a good approach. For the meantime, this workaround is great! Cheers!
Hi,
Issue:
I'm using the row selection feature in
reactable
and settingselection = "single"
. The intention of this feature seems to function similarly to radio buttons. However, I'm finding that I can deselect the currently selected row, resulting in no rows selected at all.Solution?
This behaviour seems counterintuitive for single selection mode, so I'm curious whether this is on purpose or indeed a bug?
Is it possible to add this feature (or perhaps a toggle) to ensure that a row must be selected at all times?
Reprex:
Video highlighting issue:
https://github.com/user-attachments/assets/81cdd052-1379-44cd-85fa-6612b40dc444
Thanks! :)
The text was updated successfully, but these errors were encountered: