我有一个简单闪亮的仪表板,侧面菜单中有四个选项卡,出于某种原因,当我构建闪亮的应用程序时,单击侧面菜单不会显示新页面,而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)
感谢您的帮助!
答案 0 :(得分: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"))
)
)