侧边栏页面无法在闪亮的信息中心中打开

时间:2019-08-14 15:42:29

标签: r shiny shinydashboard

我的menuItems和menuSubItems在单击时不显示。它仅保留在默认的仪表板主体上。请注意,这些子项尚未包含任何内容。我希望能够在其中包含任何数据之前打开那些页面。

我正在观看此YouTube播放列表中的教程,该教程始于视频10:https://www.youtube.com/playlist?list=PLH6mU1kedUy8c44XiTkGSEKRwojVHtsHm

 install.packages(c("shiny","shinydashboard","ggplot2","dplyr"))   
 August <- dataframe("Revenue" = c(150,275,450,890,212,618), 
                    "Team" = c(blue,blue,green,green,gold,gold))
 ui <- shinyUI(
   dashboardPage(
     dashboardHeader(title = "August 2019"),
     dashboardSidebar(
       sidebarMenu(
       menuItem("Dashboard",tabName = "dashboard"),
         menuSubItem("By Team", tabName = "by team"),
       menuItem("item2"),
       menuItem("Raw Data")
     )),
     dashboardBody(
       tabItems(
         tabItem(tabName = "dashboard",
                 fluidRow(
                   box(valueBoxOutput("totalrevenue"))
                 )),
           tabItem(tabName = "by team",
                   h1("Numbers by Team")
                   ),
           tabItem(tabName = "by customer",
             h2("Numbers by Customer")
      )))))

 server <- shinyServer(function(input,output){
   total.revenue <- sum(August$Revenue)
   output$totalrevenue <- renderValueBox({
     valueBox(
       formatC(total.revenue, format = "d", big.mark = ',')
       ,paste('Revenue:',total.revenue)
       ,icon = icon("stats", lib = 'glyphicon')
       ,color = "blue")
   })
 })
 shinyApp(ui, server)

我只需要能够在仪表板上的页面之间切换即可。

1 个答案:

答案 0 :(得分:0)

似乎tabName = "by team"不喜欢空白处。您还必须命名所有标签。尝试关注


ui <- shinyUI(
  dashboardPage(
    dashboardHeader(title = "August 2019"),
    dashboardSidebar(
      sidebarMenu(
        menuItem("Dashboard",tabName = "dashboard"),
        menuSubItem("By Team", tabName = "byteam"),#remove empty space
        menuItem("item2", tabName = "item2"), #give tab name
        menuItem("Raw Data",tabName = "rawdata") #give tab name
      )),
    dashboardBody(
      tabItems(
        tabItem(tabName = "dashboard",
                fluidRow(
                  box(valueBoxOutput("totalrevenue"))
                )),
        tabItem(tabName = "byteam", #remove empty space
                h1("Numbers by Team")
        ),
        tabItem(tabName = "item2",
                h2("Numbers by Customer Tab")
                ),
        tabItem(tabName = "rawdata",
                h2("Raw Data Tab")
        )))))

server <- shinyServer(function(input,output){
  total.revenue <- sum(August$Revenue)
  output$totalrevenue <- renderValueBox({
    valueBox(
      formatC(total.revenue, format = "d", big.mark = ',')
      ,paste('Revenue:',total.revenue)
      ,icon = icon("stats", lib = 'glyphicon')
      ,color = "blue")
  })
})
shinyApp(ui, server)

希望有帮助!