闪亮 + DT:单细胞选择

6
我正在尝试使用DT包的开发版本(可在devtools::install_github('rstudio/DT')中找到)来启用闪亮应用程序中的单个单元格选择。我已经能够使用selectiontarget参数使选择成为单元格;但是,我无法弄清楚如何禁用选择多个单元格。是否有另一个selection参数列表的参数可以允许我将用户的选择限制为最多1个单元格?如果没有,是否有其他方法实现单个单元格选择?
如果有更简单的解决方案,我非常愿意回到CRAN上的DT稳定版本。
library(shiny)
library(DT)
data("mtcars")

ui <- shinyUI(
  fluidRow(
    DT::dataTableOutput("myDatatable"),
    verbatimTextOutput("selectedCells")
  )
)

server <- shinyServer(function(input, output, session) {
  output$myDatatable <- DT::renderDataTable(mtcars, 
                                            selection=list(target="cell"),
                                            server = FALSE,
                                            rownames=FALSE)

  output$selectedCells <- renderPrint(input$myDatatable_cells_selected)
})

shinyApp(ui, server)
1个回答

11

问题出在你调用 DT::renderDataTableselection 列表中。你需要使用 selection=list(mode="single", target="cell")

mode 可以设置为 single 或 multiple,而你之前的代码中是使用了 selection(修改之前的代码)


1
还有一种模式,只允许每行选择一个吗? - JdP
@JdP 您是指选择整行还是行内的一个单元格? - Mark
1
我指的是一行中的一个单元格,因此对于每一行都有一个选择选项。 - JdP
我仍在努力寻找这个 - 每行只有一个单元格 - 但是非常难找。 - lejdale

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接