Это только частичное решение (см. edit ниже для полностью рабочего решения) . Работает только при двойном нажатии на строку. При третьем щелчке строка отменяется, я не знаю почему. Может быть, эксперт в datatables
может помочь.
library(shiny)
library(DT)
shinyApp(
ui <- shinyUI(
fluidPage(
DTOutput("test")
)
),
server <- shinyServer(function(input, output, session) {
output$test <- renderDT({
datatable(head(iris), selection = list(mode="single", target="row"),
extensions = c("Select"), options = list(select=TRUE),
callback = JS("
table.on('user-select',
function (e, dt, type, cell, originalEvent) {
if ($(cell.node()).parent().hasClass('selected')) {
e.preventDefault();
}
});"))
})
})
)
EDIT
Я нашел решение (я не совсем понимаю).
server <- shinyServer(function(input, output, session) {
output$test <- renderDT({
datatable(head(iris), selection = list(mode="single", target="row", info=FALSE),
extensions = c("Select"), options = list(select=TRUE),
callback = JS("
table.on('user-select',
function (e, dt, type, cell, originalEvent) {
if ($(cell.node()).parent().hasClass('selected') || e.result === undefined) {
e.preventDefault();
$(cell.node()).parent().addClass('selected')
return false;
}
});")
)
})
})