2016-09-01 129 views
2

我试图使用DT包的开发版本(可在devtools::install_github('rstudio/DT')处)启用单个单元格在闪亮应用程序中的选择。我已经能够使用targetselection的参数进行选择。但是,我不知道如何禁用多个单元格被选中。是否有selection参数列表的另一个参数,这将允许我将用户的选择限制为最多1个单元?如果没有,是否有另一种方法来完成单细胞选择?Shiny + DT:单元格选择

如果使用该版本的软件包有更简单的解决方案,我很乐意恢复到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) 

回答

4

的问题是你在selection列表调用DT::renderDataTable。您需要selection=list(mode="single", target="cell")

mode套单个或多个地方你有selection(您编辑之前)