我想知道是否可以修改以下闪亮的应用程序并将
sliderInput
放入侧边栏部分:
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "DB manager"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
)
),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "dashboard",
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
)
)
),
# Second tab content
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
)
)
)
server <- function(input, output) {
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)
类似的东西:
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "DB manager"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"),
sliderInput("slider", "Number of observations:", 1, 100, 50)),
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
)
),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "dashboard",
fluidRow(
box(plotOutput("plot1", height = 250))
)
),
# Second tab content
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
)
)
)
server <- function(input, output) {
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)
但这不起作用! 知道我如何才能实现这一目标吗?
当你有一个子项时,你需要定义另一个menuItem或menuSubItem。 尝试下面的代码。 请注意(在下面的代码中)您无法访问 tabName
dashboard
,而只能访问 dashboard2
。
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"),
sliderInput("slider", "Number of observations:", 1, 100, 50),
menuItem("Dashboard2", tabName = "dashboard2", icon = icon("dashboard"))
),
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
)