DT中切换table个页面时如何保存回调事件改变的行样式?

How to store row style changed by callback event when switching between table pages in DT?

我正在尝试在 Shiny 应用程序中创建一个 table,用户可以在其中双击突出显示行。

这是我的代码:

require(shiny)
require(DT)

js.highlight.func <- "table.on('dblclick','tr',function(){$(this).toggleClass('red')})"

shinyApp(
    ui = fluidPage(
        tags$head(
            tags$style(HTML(".red { background-color: red !important; }"))
            ),
        DTOutput('tbl')),
    server = function(input, output) {
        output$tbl = renderDT(
            callback = JS(js.highlight.func),
            iris
        )
    }
)

我的问题是,当我 select 另一个 table 页面然后 return 返回时,它不会保持突出显示。

设置选项server=FALSE:

  server = function(input, output) {
    output$tbl = renderDT({
      datatable(iris, callback = JS(js.highlight.func))
    }, server = FALSE)
  }