I wanted to add the functionality of something happening after a table cell was clicked (e.g. open a modal). Because (suppose my dt is has the ID "dt") input$dt_cell_clicked
stays the same until I click a new cell, I cannot execute the same event on re-clicking that cell.
I tried working around it resetting input$dt_cell_clicked
with javascript manually. This works, but there seems to be an internal updatemarker in DT that noticed I clicked the cell before and does not set the value of input$dt_cell_clicked
to the clicked value. Is there a workaround or is this a bug?
Thanks!
Minimal example:
library(shiny)
library(shinyjs)
ui <- fluidPage(
h2("Last clicked:"),
verbatimTextOutput("last_clicked"),
actionButton("reset", "Reset clicked value"),
h2("Datatable:"),
DT::dataTableOutput("dt"),
useShinyjs(),
extendShinyjs(text = paste0("shinyjs.resetDTClick = function() { Shiny.onInputChange('dt_cell_clicked', null); }"))
)
server <- function(input, output) {
# the last clicke value
output$last_clicked <- renderPrint({
str(input$dt_cell_clicked)
})
output$dt <- DT::renderDataTable({
DT::datatable(head(mtcars, 2))
})
observeEvent(input$dt_cell_clicked, {
validate(need(length(input$dt_cell_clicked) > 0, ''))
alert("You clicked something!")
})
observeEvent(input$reset, {
js$resetDTClick()
})
}
shinyApp(ui, server)