R Shiny:datatableoutput 放在 tabItems 中时不显示

R Shiny: datatableoutput not displaying when placed inside tabItems

tabItems 或数据table输出在我这边表现得很奇怪。 如果我通过注释掉 tabItems(如下所示)运行 具有以下代码的应用程序,它会向我显示 table。 但是,当我将 tabItems 放回代码中时,它会在我的浏览器中显示一个空白屏幕。完全没有错误信息。

谁能帮我看看问题出在哪里?

## app.R ##
library(shiny)
library(shinydashboard)
library(DT)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    # tabItems(
      # tabItem(
tabName = "dashboard",
fluidRow(
  column(
    width = 8,
    align = "center",
    dataTableOutput("tbl_cars")
  )
)
      # )
    # )
  )
)

server <- function(input, output) { 
  output$tbl_cars <- renderDataTable({
    datatable(mtcars)
  })
}

shinyApp(ui, server)

## sessionInfo() ##
locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8   
 [6] LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C           LC_TELEPHONE=C        
[11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] DT_0.19               shinydashboard_0.7.2  shiny_1.7.1          

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7        rstudioapi_0.13   magrittr_2.0.1    xtable_1.8-4      R6_2.5.1          rlang_0.4.11     
 [7] fastmap_1.1.0     tools_4.1.1       cli_3.0.1         jquerylib_0.1.4   withr_2.4.2       crosstalk_1.1.1  
[13] htmltools_0.5.2   ellipsis_0.3.2    yaml_2.2.1        digest_0.6.28     fontawesome_0.2.2 lifecycle_1.0.1  
[19] crayon_1.4.1      later_1.3.0       htmlwidgets_1.5.4 sass_0.4.0        promises_1.2.0.1  cachem_1.0.6     
[25] mime_0.12         compiler_4.1.1    bslib_0.3.1       jsonlite_1.7.2    httpuv_1.6.3

您需要定义选项卡的外观,例如

## app.R ##
library(shiny)
library(shinydashboard)
library(DT)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(sidebarMenu(
    menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
  )),
  dashboardBody(
    tabItems(
     tabItem(
    tabName = "dashboard",
    fluidRow(
      column(
        width = 8,
        align = "center",
        dataTableOutput("tbl_cars")
      )
    )
    )
     )
  )
)

server <- function(input, output) { 
  output$tbl_cars <- renderDataTable({
    datatable(mtcars)
  })
}

shinyApp(ui, server)