如何从R Shiny中的数据表中删除第一列(索引) [英] How to remove the first column (index) from data table in R Shiny

查看:184
本文介绍了如何从R Shiny中的数据表中删除第一列(索引)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

例如,(1, 2、3)在名称列之前,如下图所示:

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

下面是我的代码:

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/ 获得。我强烈建议您通读。

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

无论如何,请使用<$ c提供的 rownames = FALSE 参数。 c $ c> DT 包如下:

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)

这篇关于如何从R Shiny中的数据表中删除第一列(索引)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆