数据表没有显示出光泽

时间:2018-02-03 19:22:40

标签: r datatable shiny shinydashboard dt

我一直在使用相同的代码来渲染DT::datatable使用闪亮但是从昨天起它似乎不起作用。当我启动应用程序时,我的数据表未显示。但是,当我在RStudio中使用时,它会显示表格。

这是我的代码:

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

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

enter image description here

当我像这样使用RStudio中的命令时,它可以工作:

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

enter image description here

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

enter image description here

这是sessionInfo:

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

请告知。

UPDATE :根据一些评论,我在server.R中移动了数据表,如下所示:

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之前它会显示表格?

1 个答案:

答案 0 :(得分:1)

为了使其有效,我认为您必须提供另外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)