我正在设计一个 Shiny 应用程序,根据各种指标对人们进行排名。使用 DT 排序功能,我希望用户能够单击任何列并对其进行排序。
使用行名作为排名似乎很自然;问题是这些数字与表格的其余部分一起排序。有什么方法可以冻结此列,以便在表格的其余部分进行排序时排名数字保持不变?也许使用 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)
Run Code Online (Sandbox Code Playgroud) 我在 Shiny 中创建了一个数据表,它使用 DT 根据一组隐藏列中的值来设置值的样式。该表显示公司的各个部门是否达到了通话和电子邮件目标。
问题是,当我隐藏列(使用columnDefs = list(list(targets = c(4, 5), visible = FALSE)))时,我无法再rownames = FALSE在datatable()调用下使用:表显示没有数据。有谁知道我如何才能使这两个选项一起工作?
我使用过以下文章:
https://rstudio.github.io/DT/010-style.html
在 R闪亮中使用 DT::renderDataTable 时如何抑制行名称?
library(shiny)
library(tidyverse)
library(DT)
x <- tibble(
Unit = c("Sales", "Marketing", "HR"),
Calls = c(100, 150, 120),
Emails = c(200, 220, 230),
Calls_goal = c(1, 0, 0),
Emails_goal = c(0, 1, 1)
)
ui <- fluidPage(
mainPanel(
DT::dataTableOutput("table")
)
)
server <- function(input, output) {
output$table <- DT::renderDataTable({
# Can't use both visible …Run Code Online (Sandbox Code Playgroud)