不在 shinydashboard 的 menusubItems 中显示图表(使用 highcharter)

Not showing charts in menusubItems in shinydashboard (with highcharter)

我连续几个小时都在尝试让它工作,但它不起作用。我只是希望在此仪表板中为不同的选项卡呈现图表。我尝试使用 renderHighchart2 和 highchartOutput2 用 box() 将它封闭起来。图表在外面闪闪发光就好了,有什么问题吗?

编辑:我指的图表是highcharts,而不是valueboxes!此外,该应用程序确实为每个图形和 fluidRow 显示了正确的标题,但是无法绘制 highcharts

这是代码:

       library(shiny)
        library(shinydashboard)
        library(highcharter)
        library(tidyverse)
        
        
        ui <- dashboardPage(
          skin = "purple",
          dashboardHeader(title = h4(HTML("Generic company name<br/>Something to analyze")),
                          titleWidth = 275),
          dashboardSidebar(
            sidebarMenu(
              menuItem("Dashboard",icon = icon("dashboard"),
                       menuSubItem('Samenvatting', tabName = "samenvatting", icon = icon('atlas')),
                       menuSubItem('Statusverloop', tabName = "statusverloop", icon = icon('battery-three-quarters')),
                       menuSubItem('Tijdsverloop', tabName = "tijdsverloop", icon = icon("hourglass-end")),
                       menuSubItem('Affiliates', tabName = "affiliates", icon = icon("handshake")),
                       menuSubItem('Klanten informatie', tabName = "klanteninformatie", icon = icon("address-card"))
              ),
              menuItem("Kijkglas",tabname = "kijkglas",icon = icon("search"))
            )
          ),
          dashboardBody(
            tabItems(
              tabItem(tabName = 'samenvatting',
                      #contents
                      fluidRow(
                        valueBoxOutput("YTDnieuweA"),
                        valueBoxOutput("YTDomvangA")
                      ),
                      fluidRow(
                        valueBoxOutput("YTDnieuweP") ,
                        valueBoxOutput("YTDomvangP")
                      ),
                      fluidRow(
                        column( width = 6,h4("Wekelijkse statistieken", align = 'center'), highchartOutput('a') ),
                        column( width = 6,h4("Wekelijkse totale statistieken", align = 'center'), highchartOutput('b'))
                      )
              ),
              tabItem(tabName = "statusverloop"
                      #Empty TODO:
                      
              ),
              tabItem(tabName = "tijdsverloop"
                      #EMPTY: TODO
                      
              ),
              tabItem(tabName = "affiliates",
                      fluidRow(
                        column( width = 6,h4("Affiliates over aanmeldingen", align = 'center'), highchartOutput('a') ),
                        column( width = 6,h4("Affiliates over passen", align = 'center'), highchartOutput('b'))
                      )
              ),
              tabItem(tabName = "klanteninformatie",
                      fluidRow(
                        column( width = 4,h4("Wekelijkse statistieken", align = 'center'), highchartOutput('a') ),
                        column( width = 4,h4("Wekelijkse totale statistieken", align = 'center'), highchartOutput('b')),
                        column( width = 4,h4("Wekelijkse totale statistieken", align = 'center'), highchartOutput('a'))
                      )
              )
            )
          )
        )
    
server <- function(input, output) {
  output$a <- renderHighchart2({
    
    hc <- highcharts_demo() %>%
      hc_rm_series("Berlin") %>% 
      hc_chart(type = 'line')
    
    
      theme <- sandsignika = hc_theme_sandsignika()

      hc <- hc %>% hc_add_theme(theme)
      
    }
    
    hc
  })
  output$b <- renderHighchart2({
    
    hc <- highcharts_demo() %>%
      hc_rm_series("Berlin") %>% 
      hc_chart(type = 'line')
    

    
      theme <- hc_theme_economist()
      
      hc <- hc %>% hc_add_theme(theme)
      
    }
    
    hc
  })
}
shinyApp(ui,server)

在 shiny 中,您不能在 UI 中多次引用任何 output

尝试将图表存储在一个对象中(可以使用 reactiveValuesreactive() 来存储它),然后将该对象分配到单独的输出中。