【问题标题】:How to remove the first column (index) from data table in R Shiny如何从 R Shiny 中的数据表中删除第一列(索引)
【发布时间】:2019-08-09 07:34:21
【问题描述】:

我想知道是否有办法从 Shiny 的数据表中删除索引列(第一列)。

例如 Name 列之前的 (1, 2, 3) 列,如下图所示:

下面是我的代码:

header <- dashboardHeader(
  title = "Test"
)

sidebar <- dashboardSidebar(
)

body <- dashboardBody(
            box(title = "Test", width = 7, status = "warning", DT::dataTableOutput("df"))
)

# UI
ui <- dashboardPage(header, sidebar, body)

# Server
server <- function(input, output, session) {

  output$df = DT::renderDataTable(df, options = list(
    autoWidth = TRUE,
    columnDefs = list(list(width = '10px', targets = c(1,3)))))
    }

# Shiny dashboard
shiny::shinyApp(ui, server)

提前致谢。

【问题讨论】:

  • 为什么不在渲染的时候把它索引出来,DT::renderDataTable(df[-1], ...)

标签: html css r shiny dt


【解决方案1】:

https://rstudio.github.io/DT/ 上提供了一些关于该软件包的优秀文档,我强烈建议您通读。

无论如何,请使用DT 包提供的rownames = FALSE 参数,如下所示:

library(shinydashboard)
library(DT)

df <- mtcars

header <- dashboardHeader(
  title = "Test"
)

sidebar <- dashboardSidebar(
)

body <- dashboardBody(
  box(title = "Test", width = 7, status = "warning", DT::dataTableOutput("df"))
)

# UI
ui <- dashboardPage(header, sidebar, body)

# Server
server <- function(input, output, session) {

  output$df = DT::renderDataTable(df, rownames = FALSE,
                                  options = list(
                                    autoWidth = TRUE,
                                    columnDefs = list(list(width = '10px', targets = c(1,3)))))
}

# Shiny dashboard
shiny::shinyApp(ui, server)

【讨论】:

    猜你喜欢
    • 2013-11-26
    • 2022-06-16
    • 2017-07-07
    • 1970-01-01
    • 2014-01-30
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 2011-11-24
    相关资源
    最近更新 更多