updateBoxPlus: Collapse a boxPlus tag.

Description Usage Arguments Examples

View source: R/boxes.R

Description

Collapse a boxPlus tag.

Usage

1
2
3
4
5
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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)
}

jaropis/shinydashboardplus0.7.5 documentation built on Dec. 20, 2021, 9:06 p.m.