I've been working on some R shiny app that allows users to browse some data. It is displayed in a table and I want this table to have two functionalities:
These functionalities are supposed to work simultaneously -- e.g. user may query the table by providing some conditions, select all rows fulfilling them by using some button and then add more rows to the selection by clicking them manually.
The first functionality can be easily obtained using Select extension for DT -- and it works perfectly well.
The second functionality can be implemented by taking some input from the user and selecting appropriate rows by using dataTableProxy objects and selectRows function on the server side -- and it works perfectly well.
The problem arises when I try combining them. I know that it is not advisable, console displays warnings when mixing them, but it just seemed the fastest solution for me.
Here is some simplified code:
library(shiny)
library(DT)
ui <- fluidPage(
dataTableOutput("my_table"),
actionButton("my_button", "Select some rows")
)
server <- function(input, output, session) {
data(iris)
output[["my_table"]] <- renderDataTable(
iris,
# extensions = c("Select", "Buttons"),
# options = list(
# dom = 'Brtip',
# buttons = c("selectAll", "selectNone"),
## select = list(style = "multi+shift", items = "row")
# ),
# server = FALSE,
## selection = "none"
)
proxy <- dataTableProxy("my_table")
observeEvent(input[["my_button"]], {
proxy %>% selectRows(1:5)
})
}
shinyApp(ui, server)
Lines that are commented out turn on selection buttons and replace default built-in selection for DT with selection API implemented in Select extension -- as a result making proxy selection on server side impossible. I can leave those double-commented lines commented and it seems to work, but only at a glance. In reality default selection of shiny "loses" with extension selection, which can be proven by the fact that even though some rows are displayed as selected, "Deselect all" button is inactive.
My question is: what is the easiest way to combine those two approaches? Is there any option for "Select" extension I am missing that would enable selection by shiny proxy? I could solve it by manually implementing some callbacks for table instead of using proxy, but it seems like a lot of work and I would be grateful for any suggestion how to avoid it.