【发布时间】:2019-09-05 01:01:56
【问题描述】:
我正在构建一个包含三个部分的应用程序:
- 概述
- 详细结果
- 帮助
详细结果部分应显示多个子项的结果,一次显示一个。
我对将结果部分作为单个选项卡感兴趣,因为我不想为每个子项的每个选项卡编写代码。每个子项都有相同的,在示例中为直方图。
但是,当我运行示例时,我丢失了子项的 ID。 是否可以有这样的布局但保留所有菜单项和菜单子项的 ID?
很高兴看到替代方法。
下面是一个例子来说明这个问题。该解决方案将在概览中显示表格、任何子项的结果直方图以及帮助部分中的 HTML 输出。
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(id = "SideBarMENU",
menuItem("Overview", tabName = "OVERVIEW", selected = TRUE),
menuItem("Results", startExpanded = TRUE,
menuSubItem("Sepal.Length", tabName = "RESULTS"),
menuSubItem("Sepal.Width" , tabName = "RESULTS"),
menuSubItem("Petal.Length", tabName = "RESULTS"),
menuSubItem("Petal.Width" , tabName = "RESULTS")
),
menuItem("Help", tabName = "HELP")
)
),
dashboardBody(
tabItems(
tabItem("OVERVIEW",
box("Overview box",
tableOutput("overview"))
),
tabItem("RESULTS",
box("Results box",
plotOutput("results")
)
),
tabItem("HELP",
box("HELP box",
textOutput("help"))
)
)
)
)
server <- function(input, output, session) {
data <- reactive({
print(input$SideBarMENU)
if(input$SideBarMENU %in% names(iris)){
iris[[input$SideBarMENU]]
} else {
rnorm(100, 1000, 10)
}
})
output$results <- renderPlot({
hist(data())
})
output$overview <- renderTable({
head(iris)
})
output$help <- renderText({
HTML("A wiki is a website on which users collaboratively.....")
})
}
shinyApp(ui, server)
【问题讨论】:
标签: r shiny menuitem shinydashboard