Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shiny + DT: Single Cell Selection

Tags:

r

dt

shiny

I am trying to use the development version of the DT package (available at devtools::install_github('rstudio/DT')) to enable single cell selection in a shiny application. I have been able to make the selection be cells using the target argument for selection; however, I can't figure out how to disable multiple cells being selected. Is there another argument for the selection parameter list that will allow me to restrict the user's selection to a max of 1 cell? If not, is there another way to accomplish single cell selection?

I am very open to revert back to the stable version of DT on CRAN if there is an easier solution using that version of the package.

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)
like image 771
Adam Spannbauer Avatar asked Sep 01 '16 11:09

Adam Spannbauer


1 Answers

The problem is in your call to DT::renderDataTable in the selection list. You need selection=list(mode="single", target="cell")

mode sets single or multiple where you had selection (before your edit)

like image 128
Mark Avatar answered Oct 21 '22 00:10

Mark