簡體   English   中英

如何從R Shiny中的數據表中刪除第一列(索引)

[英]How to remove the first column (index) from data table in R Shiny

我想知道是否有辦法從 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)

提前致謝。

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM