0

I want to expand a cell in a DataTable in R Shiny when it is clicked on. I've come across the following implementation, where a user can hover over a cell to see the full contents of it:

DT::datatable(
        bgcDF,
        class = "display nowrap",
        rownames = FALSE,
        escape = FALSE,
        options = list(
          columnDefs = list(list(
            targets = c(4),
            render = JS(
              "function(data, type, row, meta) {",
              "return type === 'display' && data.length > 60 ?",
              "'<span title=\"' + data + '\">' + data.substr(0, 60) + '...</span>' : data;",
              "}")
          )),

This is the first half of what I need. If data within a cell meets this criterion and has been shortened, how can I implement a click functionality that expands the data within that cell?

Thanks

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
Mitty
  • 3
  • 1

1 Answers1

0

Perhaps by requesting editable cells but disabling the editing for all columns:

library(DT)

dat <- iris

datatable(
  dat,
  editable = list(
    target = "cell", 
    disable = list(columns = seq_along(dat))
  )
)

Then the cell contents appears when the cell is double-clicked.

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225