shinydashboardPlus (version 0.8.0.9000)

updateBoxPlus: Collapse a boxPlus tag.

Description

Collapse a boxPlus tag.

Usage

updateBoxPlus(
  inputId,
  action = c("remove", "toggle", "restore"),
  session = shiny::getDefaultReactiveDomain()
)

Arguments

inputId

Box to toggle.

action

Action to trigger: either collapse, remove or restore.

session

Shiny session object.

Examples

Run this code
# NOT RUN {
if (interactive()) {
 library(shiny)
 library(shinydashboard)
 library(shinydashboardPlus)
 
 ui <- dashboardPagePlus(
   dashboardHeaderPlus(),
   dashboardSidebar(),
   dashboardBody(
     tags$style("body { background-color: ghostwhite}"),
     fluidRow(
       actionButton("toggle_box", "Toggle Box"),
       actionButton("remove_box", "Remove Box", class = "bg-danger"),
       actionButton("restore_box", "Restore Box", class = "bg-success")
     ),
     br(),
     boxPlus(
       title = textOutput("box_state"),
       "Box body",
       inputId = "mybox",
       collapsible = TRUE,
       closable = TRUE,
       plotOutput("plot")
     )
   )
 )
 
 server <- function(input, output, session) {
   output$plot <- renderPlot({
     req(!input$mybox$collapsed)
     plot(rnorm(200))
   })
   
   output$box_state <- renderText({
     state <- if (input$mybox$collapsed) "collapsed" else "uncollapsed"
     paste("My box is", state)
   })
   
   observeEvent(input$toggle_box, {
     updateBoxPlus("mybox", action = "toggle")
   })
   
   observeEvent(input$remove_box, {
     updateBoxPlus("mybox", action = "remove")
   })
   
   observeEvent(input$restore_box, {
     updateBoxPlus("mybox", action = "restore")
   })
   
   observeEvent(input$mybox$visible, {
     collapsed <- if (input$mybox$collapsed) "collapsed" else "uncollapsed"
     visible <- if (input$mybox$visible) "visible" else "hidden"
     message <- paste("My box is", collapsed, "and", visible)
     showNotification(message, type = "warning", duration = 1)
   })
   
 }
 
 shinyApp(ui, server)
}
# }

Run the code above in your browser using DataLab