代码之家  ›  专栏  ›  技术社区  ›  nilesguo

shinydashboard选项卡项目不工作

  •  1
  • nilesguo  · 技术社区  · 6 年前

    我有一个简单的闪亮仪表板,侧菜单中有四个选项卡,出于某种原因,当我构建闪亮的应用程序时,单击侧菜单不会显示新页面,而tab2的内容只会附加到tab1。

    搜索stackoverflow时向我显示了以下问题: Shinydashboars tabItems not working properly ,答案不适用于我,因为我没有使用rmd,我也不打算将其托管到AWS服务器。

    以下是参考代码:

    ui <- dashboardPage(
    dashboardHeader(title = "Study Dashboard"),
    dashboardSidebar(
    sidebarMenu(
      menuItem("Overall Objectives", tabName = "objectives"),
      menuItem("Wellpad Operator", tabName = "wellpad_operator"),
      menuItem("Wastewater Expert", tabName = "wastewater_expert"),
      menuItem("Freshwater Expert", tabName = "freshwater_expert"),
      menuItem("Environmental Impact", tabName = "environ_impact")
    )
    ),
    dashboardBody(
    #Tab 1 Objective View
    tabItems(
      tabItem(tabName = "objectives", 
              h2("Overall Objectives"),
              fluidRow(
                box(
                  title = "Overall Objective Comparison", width = 6, solidHeader = TRUE,
                  plotOutput("objective_plot")
                ),
                box(
                  title = "Cost Category Breakdown", width = 6, solidHeader = TRUE,
                  plotOutput("costbreakdown_plot")
                ),
                box(
                  title = "Decision Variables", width = 12, solidHeader = TRUE,
                  tableOutput("decision_table"))
              ))
    ),
    
    #Tab 2 Wellpad Decision
    tabItem(tabName = "wellpad_operator", 
            h2("Wellpad Operator") 
            ),
    
    #Tab 3 Wastewater Expert
    tabItem(tabName = "wastewater_expert",
            h2("Wastewater Expert")
            ),
    
    #Tab 4 Freshwater Expert
    tabItem(tabName = "freshwater_expert",
            h2("Freshwater Expert")
            ),
    
    #Tab 5 Environmental Damages
    tabItem(tabName = "environ_impact",
            h2("Environmental Impact"))
    )
    )
    
    server <- function(input, output) {
    #server side code that generates the plots
    }
    
    shinyApp(ui = ui, server = server)
    

    谢谢你的帮助!

    1 回复  |  直到 6 年前
        1
  •  3
  •   kluu    6 年前

    你需要把你所有的 tabItem 在…内 tabItems 。请尝试以下操作:

    dashboardBody(
        #Tab 1 Objective View
        tabItems(
          tabItem(tabName = "objectives", 
                  h2("Overall Objectives"),
                  fluidRow(
                    box(
                      title = "Overall Objective Comparison", width = 6, solidHeader = TRUE,
                      plotOutput("objective_plot")
                    ),
                    box(
                      title = "Cost Category Breakdown", width = 6, solidHeader = TRUE,
                      plotOutput("costbreakdown_plot")
                    ),
                    box(
                      title = "Decision Variables", width = 12, solidHeader = TRUE,
                      tableOutput("decision_table"))
                  )),
          #Tab 2 Wellpad Decision
          tabItem(tabName = "wellpad_operator", 
                  h2("Wellpad Operator") 
          ),
    
          #Tab 3 Wastewater Expert
          tabItem(tabName = "wastewater_expert",
                  h2("Wastewater Expert")
          ),
    
          #Tab 4 Freshwater Expert
          tabItem(tabName = "freshwater_expert",
                  h2("Freshwater Expert")
          ),
    
          #Tab 5 Environmental Damages
          tabItem(tabName = "environ_impact",
                  h2("Environmental Impact"))
        )
    )