0

I want my accordion to overflow into the body instead of making my sidebar scroll. I want the same behavior I am getting from my virutal select inputs. I have tried changing the class but I have no clue what I am doing.

library(tidyverse)
library(shiny)
library(bslib)
library(shinyWidgets)

ui <- page_sidebar(
    
    sidebar = sidebar(
    
    virtualSelectInput(
        inputId = "idk", 
        label = "idk", 
        choices = replicate(10, expr =  str_flatten(sample(letters, size = 45, replace = T))),
        multiple = T, search = T
        ),
        
    virtualSelectInput(
        inputId = "idk", 
        label = "idk", 
        choices = replicate(10, expr =  str_flatten(sample(letters, size = 45, replace = T))),
        dropboxWrapper = "body",
        dropboxWidth = "400px"
    ),
    
    accordion(
        open = F,
        accordion_panel(
            title = "Test",
            
            virtualSelectInput(
                inputId = "idk", 
                label = "idk", 
                choices = replicate(10, expr =  str_flatten(sample(letters, size = 45, replace = T))),
                multiple = T, search = T
            ),
            
            virtualSelectInput(
                inputId = "idk", 
                label = "idkasdfjasdlkfhjasdkljfhasdkjlfhadksljhdakjs", 
                choices = replicate(10, expr =  str_flatten(sample(letters, size = 45, replace = T))),
                dropboxWrapper = "body",
                dropboxWidth = "400px"
            
            )
    )
      
)
)
)

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

I dont know much about css or hrml.

kmlewis15
  • 25
  • 3

1 Answers1

0

To make the accordion extend past the sidebar and overflow into the body, similar to the behavior you get from your virtualSelectInput, you'd typically need to override the default CSS behavior of the accordion to prevent it from being constrained by the sidebar's boundaries.

However, there are a few things to consider:

Bootstrap Version: shinyWidgets and shiny use Bootstrap to style UI elements. By default, Shiny uses Bootstrap 3, but the bslib library allows for the use of Bootstrap 4. Depending on the version, there might be different classes and styles applied.

Unique IDs: It's essential to provide unique IDs to your input elements. Repeated use of the same ID ("idk") will cause unpredictable behavior in your Shiny app.

CSS Overriding: To override the default behavior, you'd likely need to adjust some CSS properties such as overflow and position. Adding custom CSS to a Shiny app can be done using the tags$style() function.

ui <- page_sidebar(

# Add custom CSS
tags$head(
    tags$style(HTML("
        .sidebar {
            overflow: visible;
        }
        
        .accordion {
            position: relative;
            z-index: 1000;  # Ensure it's on top of other elements
        }
    "))
),

sidebar = sidebar(
  # ... your sidebar content here ...
)
)

    server <- function(input, output, session) {
      
    }
    
    shinyApp(ui, server)

In this example:

.sidebar CSS class might refer to the sidebar container. By setting its overflow to visible, it allows contained elements to extend outside of it. .accordion CSS class is a guess (you may need to inspect your HTML or consult shinyWidgets documentation for the exact class) which aims to ensure the accordion appears above other elements by setting its z-index. Keep in mind that my answer provides a generic approach. Depending on the exact CSS classes and styles used by your Shiny app and the versions of libraries you're using, you might need to adjust the solution. Using browser developer tools can help you pinpoint the exact CSS rules and classes affecting the accordion's behavior, which will make overriding them more precise.