【问题标题】:shinydashboard tabItems not working闪亮的仪表板选项卡项目不起作用
【发布时间】:2018-04-19 04:32:09
【问题描述】:

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

虽然搜索 * 向我展示了这个问题: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)

感谢您的帮助!

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    您需要将所有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"))
        )
    )
    

    【讨论】:

    • 哇,这对我来说是一个愚蠢的错误。教我不要正确跟踪我的括号。感谢您为我挖掘这个!
    • Shiny 时常发生在我身上!对应的括号可以相距很远...
    最近更新 更多