【问题标题】:Data table will not work in shinydashboard数据表在闪亮仪表板中不起作用
【发布时间】:2020-10-27 19:34:11
【问题描述】:

如果 shinydashboard 是一个人,我想在黑暗的小巷里拿着棒球棒见到他。我只是想在我闪亮的应用程序中将数据框显示为表格,所以我在网上查看了一堆网站和关于堆栈交换的问题,这就是我得到的。

用户界面

library(shiny)
library(shinydashboard)
library(data.table)#For fread.
library(tidyverse)
library(htmlwidgets)
library(DT)#For the interactive table.


# Header -----------------------------------------------------------------------|
header<-dashboardHeader( title = "Marketing Dashboard"
  
)


# Sidebar ----------------------------------------------------------------------|

sidebar<-dashboardSidebar(
  sidebarMenu(
    menuItem("Overview", tabname ="overview", icon = icon("dashboard")),
    menuItem("Weather", tabname ="weather", icon = icon("bolt"))
  )
)

# Body -------------------------------------------------------------------------|
  
body<-dashboardBody( 
  tabItems(
    tabItem(tabName = 'overview',
        DT::dataTableOutput("overviewtable")
    ),
    tabItem(tabName = 'weather',
      fluidRow(
        
      )
    )
  )
)



# UI ---------------------------------------------------------------------------|

ui = dashboardPage(
  header,
  sidebar,
  body
)

shinyApp(ui,server)

服务器

server <- function(input,output){
  
  #Table for overview
  output$overviewtable<- DT::renderDataTable({
    DT::datatable(tib1)
  })
  
}

我尝试过使用tableOutputrenderTable 我试图查看我的 tib1 是否存在某种问题,因此我尝试使用数据集 mpg。那没有用。我尝试将 DT::dataTableOutput("overviewtable") 放在一个列()中,在一个fluidRow 中。我尝试重新安装 DT 的软件包并刷新 R,但没有奏效。我从 R here 查看了画廊网站。我拿了那个代码并运行它,我能够看到他们制作的表格,但是当我运行我的代码时,我根本看不到我的表格或其他表格。我觉得它与 Shinydashboard 有关,因为似乎当我从上面的网站运行代码时,它只是使用了 Shiny,它起作用了。

【问题讨论】:

    标签: r shiny datatable shinydashboard dt


    【解决方案1】:

    问题是tabName = 参数中的拼写错误:

    sidebar<-dashboardSidebar(
      sidebarMenu(
        menuItem("Overview", tabName ="overview", icon = icon("dashboard")),
        menuItem("Weather", tabName ="weather", icon = icon("bolt"))
      )
    )
    

    【讨论】:

    • 当我运行代码时,我不会收到任何错误消息,我什至会看到两个选项卡,但这确实是问题所在。谢谢!
    最近更新 更多