ebailey78 / shinyBS

Twitter Bootstrap Components for Shiny
182 stars 47 forks source link

Size of bsCollapsePanel does not change when content is invalidated #103

Open afstam opened 5 years ago

afstam commented 5 years ago

I'm writing a Shiny app with bsCollapsePanels that contain datatables. When the size of the datatable changes, the size of the panel changes as well. However, when the dataTableOutput is invalidated (through the shiny:::validate function), the size of the panel remains the same. This causes the panel to be unneccessarily large, or to be too small so that the warning message extends beyond the panel.

See a reproducible example of this behaviour below:

library(shiny)
library(shinyBS)
library(DT)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput("myselect", "Show table?",
                  choices = c("No", "Big", "Small"), 
                  selected = "No")
    ),
    mainPanel(
      bsCollapse(
        bsCollapsePanel(title = "panel", dataTableOutput("mytext"), style = 'primary'),
        id = "collapsepanel", multiple = TRUE, open = "panel"
      )
    )
  )
)

server <- function(input, output, session) {
  output$mytext <- renderDataTable({
    validate(
      need(input$myselect != "No", "Output invalidated.")
    )

    if (input$myselect == "Big")
      return(datatable(data.frame(a = runif(100), b = 3)))

    if (input$myselect == "Small")
      datatable(data.frame(a = runif(1), b = 3))
  })
}

shinyApp(ui = ui, server = server)