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

你说的曾经没有我的故事 提交于 2020-08-27 22:12:29

问题


I am wondering if there is a way to remove the index column (1st column) from the data table in Shiny.

For example, column of (1, 2, 3) before Name column as shown in the screenshot below:

Below is my code:

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)

Thanks in advance.


回答1:


There is some excellent documentation of the package available at https://rstudio.github.io/DT/ I would highly recommend reading through.

At any rate, use the rownames = FALSE argument provided by the DT package as follows:

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)


来源:https://stackoverflow.com/questions/55229736/how-to-remove-the-first-column-index-from-data-table-in-r-shiny

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!