【问题标题】:R Shiny - Pre-selection of rows in Select extension for DatatablesR Shiny - 在数据表的选择扩展中预选行
【发布时间】:2020-03-15 14:16:21
【问题描述】:

如何使用 Shiny 中的 Datatables 的 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 = list(selected = 1:3) 将不起作用。

【问题讨论】:

标签: r shiny dt


【解决方案1】:

没有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)

【讨论】:

猜你喜欢
  • 2019-08-25
  • 1970-01-01
  • 1970-01-01
  • 2016-05-12
  • 2015-08-25
  • 2017-06-13
  • 2016-10-06
  • 2019-06-22
  • 2016-09-15
相关资源
最近更新 更多