R Shiny-在数据表的选择扩展名中预选择行 [英] R Shiny - Pre-selection of rows in Select extension for Datatables

查看:63
本文介绍了R Shiny-在数据表的选择扩展名中预选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Shiny中预选带有数据表的选择"扩展名的行?我在这里检查了文档: https://datatables.net/extensions/select/.但我不知道.我尝试指定 rows = 1:3 ,但这没有任何效果:

How can I pre-select rows with the Select extension for Datatables in Shiny? I've checked the documentation here: https://datatables.net/extensions/select/. But I can't figure it out. I tried specifying rows = 1:3 but that didn't have any effect:

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)

  }
)

NB.我正在为数据表使用Select扩展名,而不是DT包的行选择实现.因此 selection = list(selected = 1:3)将不起作用.

NB. I am using the Select extension for Datatables, not the DT package's implementation of row selection. So selection = list(selected = 1:3) will not work.

推荐答案

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

There's no select.rows option. You can use a callback:

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)

这篇关于R Shiny-在数据表的选择扩展名中预选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆