You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ShinyApp中无法显示表格行名的技术求助

Fixing Missing Row Names in Shiny DataTable

Hey there! I noticed your Shiny app isn’t displaying row names for your table—this is a quick fix since DataTables don’t show row names by default. Here’s how to resolve it:

The Issue

By default, the renderDataTable() function (which uses the DT package under the hood) hides row names to keep tables clean. To make your custom row labels (a-f) visible, you just need to explicitly enable this setting.

Solution 1: Quick Toggle with rownames = TRUE

You can directly pass the rownames parameter to renderDataTable() to turn row names on. Here’s your modified server code:

server <- function(input, output) {
  output$table <- renderDataTable({
    myData
  }, rownames = TRUE) # This line enables row names
}

Solution 2: Full Control with datatable()

If you want more flexibility over table styling or options, use the datatable() function from the DT package (just remember to load it first). This lets you explicitly enable row names and tweak other settings later:

library(shinydashboard)
library(shiny)
library(DT) # Add this line to load the DT package

myData <- matrix(
 data=c('13,867','$229,153','30,128','$16.53','98.17%','39.69%'),
 nrow = 6, ncol = 1,
 dimnames = list(letters[1:6], c("Metrics"))
)

ui <- dashboardPage(
 dashboardHeader(),
 dashboardSidebar(),
 dashboardBody(
 box(dataTableOutput("table"))
 )
)

server <- function(input, output) {
 output$table <- renderDataTable({
   datatable(myData, rownames = TRUE) # Enable row names here
 })
}

shinyApp(ui, server)

Either approach will make your row names a through f appear alongside your metrics data.

内容的提问来源于stack exchange,提问作者AM_123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:39:17