Hi there,
I need to add a custom button on specific DT rows. Everything works fine, except for the fact that once you make a click on a row, Shiny on the Server side does not accept more clicks from the same button. If I click on a button in a different row, everything works, but I cannot click twice on the same button. The event is not fired.
Any suggestions?
Here is a snippet of code.
library(shiny)
library(DT)
library(dplyr)
library(tidyr)
data <- data.frame(
col1 = c("Total", "Account", "Account", "Total"),
col2 = c(1, 2, 3, 4)
)
data <- data %>%
mutate(
button = case_when(
col1 == "Account" ~ sprintf(
'Click me',
col2, "Shiny.setInputValue('button', this.id);"),
TRUE ~ NA_character_
)
)
ui <- fluidPage(
fluidRow(
column(
width = 6,
DTOutput("tbl1", height = "500px")
)
)
)
server <- function(input, output){
output[["tbl1"]] <- renderDT({
datatable(data, escape = F, fillContainer = TRUE, selection = 'none')
})
observeEvent(input[["button"]], {
print('fired')
splitID <- strsplit(input[["button"]], "_")[[1]]
row <- splitID[2]
showModal(modalDialog(
title = paste0("Row ", row, " clicked"),
size = "s",
easyClose = TRUE,
footer = NULL
))
})
}
shinyApp(ui, server)