Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggling boxes to collapse has unexpected results with nested boxes #395

Open
rwhitt221 opened this issue May 5, 2023 · 1 comment
Open

Comments

@rwhitt221
Copy link

rwhitt221 commented May 5, 2023

Good afternoon.

First off this is a beautiful package and is hugely useful.

I like to guide the user by using boxes and collapsing/uncollapsing the next element as they travel through the app.

I also often nest boxes, particularly when I am using modules to develop.

I've noticed that when you nest boxes, you get unexpected results when you toggle their collapsed state. If you toggle the highest level, it will often collapse other boxes but leave the upper box open, but the plus minus sign on the box will flip without actually having an effect.

Interestingly, if the user toggles the box with the plus minus, the "correct" behaviour occurs. I just don't seem to be able to replicate this with code.

Below is a reprex.

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

ui <- dashboardPage(
  title = "Box API",
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    tags$style("body { background-color: ghostwhite}"),
    fluidRow(
      actionButton("toggle_box", "Toggle Box")
    ),
    br(),
    box(
      title = textOutput("box_state"),
      id = "mybox",
      collapsible = TRUE,
      closable = TRUE,
      box(
        title = textOutput("box_state2"),
        id = "mybox2",
        collapsible = TRUE,
        closable = TRUE
      )
    )
  )
)

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)
  })

  output$box_state2 <- renderText({
    state <- if (input$mybox2$collapsed) "collapsed" else "uncollapsed"
    paste("My box is", state)
  })

  observeEvent(input$toggle_box, {
    updateBox("mybox", action = "toggle")
  })

  observeEvent(input$update_box, {
    updateBox(
      "mybox",
      action = "update",
      options = list(
        title = h2("New title", dashboardLabel(1, status = "primary")),
        status = "danger",
        solidHeader = TRUE,
        width = 4
      )
    )
  })

  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)

Many thanks and all the best. Keep up the good work.

@YongbingDing

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants