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

controlbar forgets collapsed = FALSE, when using conditionalPanel to render the controlbar content #385

Open
fernandoroa opened this issue Dec 19, 2024 · 0 comments

Comments

@fernandoroa
Copy link

fernandoroa commented Dec 19, 2024

This example includes a workaround to keep collapsed = FALSE, which is not respected when using conditionalPanel

library(shiny)
library(bs4Dash)

shinyApp(
  ui = dashboardPage(
    header = dashboardHeader(
      title = "My dashboard"
    ),
    sidebar = dashboardSidebar(
      sidebarMenu(
        id = "sidebarMenu",
        menuItem(
          text = "Tab 1",
          tabName = "tab1"
        ),
        menuItem(
          text = "Tab 2",
          tabName = "tab2"
        ),
        menuItem(
          text = "Tab 3",
          tabName = "tab3"
        )
      )
    ),
    body = dashboardBody(
      tags$script(HTML("
        $(document).on('shiny:inputchanged', function(event) {
          if (event.name === 'sidebarMenu') {
            setTimeout(function() {
              if (!$('body').hasClass('control-sidebar-slide-open')) {
                $('#controlbar-toggle').click();
              }
            }, 100); 
          }
        });
      "))
    ),
    controlbar = dashboardControlbar(
      id = "controlbar",
      collapsed = FALSE,
      conditionalPanel(
        condition = "input.sidebarMenu=='tab1'",
        controlbarMenu(
          controlbarItem(title = "Item1"),
          controlbarItem(title = "Item4")
        )
      ),
      conditionalPanel(
        condition = "input.sidebarMenu=='tab2'",
        controlbarMenu(
          controlbarItem(title = "Item2")
        )
      ),
      conditionalPanel(
        condition = "input.sidebarMenu=='tab3'",
        controlbarMenu(
          controlbarItem(title = "Item3")
        )
      )
    ),
    title = "DashboardPage"
  ),
  server = function(input, output, session) { }
)
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

1 participant