【问题标题】:R Shiny: datatableoutput not displaying when placed inside tabItemsR Shiny:放置在tabItems中时不显示数据表输出
【发布时间】:2021-12-05 21:57:28
【问题描述】:

tabItems 或 datatableoutput 在我这边表现得很奇怪。 如果我通过注释掉 tabItems(如下所示)使用下面的代码运行应用程序,它会向我显示表格。 但是,当我将 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

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    您需要定义选项卡的样子,例如

    ## 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)
    

    【讨论】:

      猜你喜欢
      • 2018-02-27
      • 1970-01-01
      • 1970-01-01
      • 2018-09-30
      • 2018-07-08
      • 2021-11-26
      • 2016-05-10
      • 2022-01-15
      • 2020-04-28
      相关资源
      最近更新 更多