Shiny DT:排序时冻结行名?

Shiny DT: Freeze rownames while sorting?

我正在设计一个 Shiny 应用程序来根据各种指标对人们进行排名。使用 DT 排序功能,我希望用户能够单击任何列并按它排序。

使用行名作为排名似乎很自然;问题是这些数字与 table 的其余部分一起排序。有什么方法可以冻结此列,以便在其余 table 排序时排名数字保持不变?也许有一个 JavaScript 功能?

编辑:在下面的示例中,当我单击 "Metric_1," 时,我希望行名保留 1、2、3、4,而不是排序为 3、2、1、4 以匹配新顺序C 人、B 人、A 人、D 人。结束编辑

我在 RStudio 帮助页面上没有看到这个选项:https://rstudio.github.io/DT/

# Simplified example

library(shiny)
library(DT)


ui <- fluidPage(

    DT::dataTableOutput("table")

)

server <- function(input, output) {

    output$table <- DT::renderDataTable({

        x <- data.frame(
            Name = c("Person A", "Person B", "Person C", "Person D"), 
            Metric_1 = c(8, 7, 4, 10), 
            Metric_2 = c(3, 5, 2, 8)
        )

        datatable(x)

    })
}

shinyApp(ui = ui, server = server)

这是一个使用

的工作示例
library(shiny)
library(DT)


ui <- fluidPage(

  DT::dataTableOutput("table")

)

server <- function(input, output) {
  js <- c(
    "table.on('draw.dt', function(){",
    "  var PageInfo = table.page.info();",
    "  table.column(0, {page: 'current'}).nodes().each(function(cell,i){", 
    "    cell.innerHTML = i + 1 + PageInfo.start;",
    "  });",
    "})")

  output$table <- DT::renderDataTable({

    x <- data.frame(
      Name = c("Person A", "Person B", "Person C", "Person D"), 
      Metric_1 = c(8, 7, 4, 10), 
      Metric_2 = c(3, 5, 2, 8)
    )

    datatable(x, callback = JS(js))

  })
}

shinyApp(ui = ui, server = server)