如何从R Shiny中的数据表中删除第一列(索引)

MMA*_*ASS 7 html css r shiny dt

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

例如,名称列之前的 (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)
Run Code Online (Sandbox Code Playgroud)

提前致谢。

Mat*_*ill 7

https://rstudio.github.io/DT/ 上有一些关于该包的优秀文档,我强烈建议通读一遍。

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

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)
Run Code Online (Sandbox Code Playgroud)