Shiny DT: Freeze rownames while sorting?

白昼怎懂夜的黑 提交于 2019-12-05 11:57:43

Here's a working example using this SO answer

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)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!