操作按钮上的Onclick功能,用于滑动滑动条



下面的应用程序默认打开侧边栏。有没有办法让它默认关闭并在用户点击"释放"时滑动?按钮。当用户再次点击按钮时,侧边条应该滑动进去,这是开和关类型。我们能做到吗?

library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(plotOutput("plot1", height = 250)),

box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
),
box(actionButton("release", "Release"))
)
)
)
server <- function(input, output) {
set.seed(122)
histdata <- rnorm(500)

output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)

使用onclick事件的版本:

library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(collapsed = TRUE),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
box(plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
),
box(actionButton("release", "Release", onclick = "$('body').toggleClass('sidebar-collapse');"))
)
)
)
server <- function(input, output) {
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)

最新更新