I'm designing a Shiny app to rank people based on a variety of metics. Using the DT sorting feature, I want users to be able to click on any column and sort by it.
It seems natural to use the rownames as the rank; the problem is that these numbers sort along with the rest of the table. Is there any way to freeze this column so the rank numbers stay the same while the rest of the table sorts? Perhaps with a JavaScript function?
EDIT: In the example below, when I click "Metric_1," I want the rownames to stay 1, 2, 3, 4, instead of sorting to 3, 2, 1, 4 to match the new order of Person C, Person B, Person A, Person D. END EDIT
I don't see this option on the RStudio help page: 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)