Removing the isolation would cause the event to be triggered whenever a user clicks on a row, because the function makes reference to aTable_rows_selected. It should only be triggered when the maxButton button is clicked. With isolation retained, clicking the deselection button does nothing for the first time. It only fires the event if the button is clicked twice. Below is an example you can run easily. Is it a Shiny bug that I have discovered ? I wonder why the event isn't handled with just one click.
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
fluidRow(
dataTableOutput("aTable")
),
fluidRow(
actionButton("maxButton", "Find Maximum"), actionButton("deselectButton", "Deselect All")
),
fluidRow(textOutput("maxText"))
),
server = function(input, output, session) {
output[["aTable"]] = renderDataTable({datatable(iris, options = list(dom = 't'))})
tableProxy <- dataTableProxy("aTable")
observeEvent(c(input[["maxButton"]], input[["deselectButton"]]),
{
output[["maxText"]] <- renderText({
isolate({
selectedRows <- input[["aTable_rows_selected"]]
if(length(selectedRows) > 0)
selectedRows[which.max(iris[selectedRows, 1])]
else "Nothing."
})
})
})
observeEvent(input[["deselectButton"]],
{
selectRows(tableProxy, NULL)
})
})