R Shiny - 在数据表的 Select 扩展中预选行

R Shiny - Pre-selection of rows in Select extension for Datatables

如何在 Shiny 中为 Datatables 预 select 行扩展 Select?我在这里查看了文档:https://datatables.net/extensions/select/。但我想不通。我尝试指定 rows = 1:3 但没有任何效果:

library(DT)
library(shiny)

dat <- iris[1:17,]

shinyApp(
  ui = fluidPage(DTOutput("table")),

  server = function(input, output, session) {  

    output[["table"]] <- renderDT({
        datatable(
          dat,
          options = list(select = list(
            style = "multi", 
            rows = 1:3, 
            selector = "td:not(.notselectable)")),
          extensions = "Select", selection = "none")
    }, server = FALSE)

  }
)

注意。我正在使用 Datatables 的 Select 扩展,而不是 DT 包对行 selection 的实现。所以 selection = list(selected = 1:3) 将不起作用。

没有 select.rows 选项。您可以使用回调:

output[["table"]] <- renderDT({
  datatable(
    dat,
    callback = JS("table.rows([0,1,2]).select();"),
    options = list(select = list(
      style = "multi", 
      selector = "td:not(.notselectable)")),
    extensions = "Select", selection = "none")
}, server = FALSE)