数据表未显示在闪亮的

Datatable is not showing up on shiny

我一直在使用相同的代码使用 shiny 渲染 DT::datatable,但从昨天开始它似乎不起作用。当我启动应用程序时,我的数据table 没有显示。但是,当我在 RStudio 中使用 in 时,它显示 table.

这是我的代码:

ui.R

library(shiny)
library(shinydashboard)
library(DT)

dashboardPage(
  dashboardHeader(title = 'Test', titleWidth = 400),
  dashboardSidebar(width = 400,
                   sidebarMenu(
                     menuItem("Resources", icon = icon("database"), tabName = "rdb",
                              menuSubItem("Internal", icon = icon("database"), tabName = "rdbi")
                              )
                     )
                   ),

  dashboardBody(
    tabItems(
      tabItem(tabName = "rdbi", 
              datatable(data = read.csv('internal.csv'))
              )
      )
    )
  )

server.R

shinyServer(function(input, output, session){
})

internal.csv

Resource,Link
Sample1,Test1
Sample2,Test2
Sample3,Test3
Sample4,Test4
Sample5,Test5

当我启动应用程序时,这是我看到的:

当我像这样在 RStudio 中使用命令时,它起作用了:

datatable(data = read.csv('internal.csv'))

此外,这是我在控制台上遇到的错误:

这是会话信息:

R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] DT_0.4               shinydashboard_0.6.1 shiny_1.0.5         
[4] BiocInstaller_1.28.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.15    digest_0.6.15   mime_0.5        R6_2.2.2       
 [5] xtable_1.8-2    jsonlite_1.5    magrittr_1.5    tools_3.4.2    
 [9] htmlwidgets_1.0 crosstalk_1.0.0 httpuv_1.3.5    yaml_2.1.16    
[13] compiler_3.4.2  htmltools_0.3.6

请指教

更新:根据一些评论,我将 server.R 中的数据 table 移动如下:

ui.R

library(shiny)
library(shinydashboard)
library(DT)

dashboardPage(
  dashboardHeader(title = 'Test', titleWidth = 400),
  dashboardSidebar(width = 400,
                   sidebarMenu(
                     menuItem("Resources", icon = icon("database"), tabName = "rdb",
                              menuSubItem("Internal", icon = icon("database"), tabName = "rdbi"),
                              menuSubItem("External", icon = icon("database"), tabName = "rdbe")
                              )
                     )
                   ),

  dashboardBody(
    tabItems(
      tabItem(tabName = "rdbi", 
              DT::dataTableOutput(outputId = "table1") 
              )
      )
    )
  )

server.R

shinyServer(function(input, output, session){

  output$table1 <- DT::renderDT(expr = read.csv(file = 'internal.csv'))

})

为什么在我点击子菜单项 Internal 之前它就显示 table?

要使其正常工作,我认为您必须提供另一个 menuItem 以上资源。这将按预期工作(我使用 iris 来 运行 代码)。您可以从一个菜单切换到另一个菜单,内容会相应改变。

ui <- dashboardPage(
  dashboardHeader(), 
  dashboardSidebar(
    sidebarMenu(
      menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
      menuItem("Resources", icon = icon("database"), tabName = "rdb", startExpanded = TRUE,
               menuSubItem("Internal", icon = icon("database"), tabName = "rdbi"),
               menuSubItem("External", icon = icon("database"), tabName = "rdbe")
      )
    )
  ),
  dashboardBody(
    tabItems(
      tabItem("dashboard", "Dashboard tab content"),
      tabItem("rdbi", DT::dataTableOutput("table1")),
      tabItem("rdbe", "External tab content")
    )
  )
)

server <- function(input, output, session) {
  output$table1 <- DT::renderDT(iris)


}

shinyApp(ui, server)