Skip to content

[BUG] bs4Dash navbarMenu() issue using Gollem #1186

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

Open
HugoGit39 opened this issue Mar 7, 2025 · 2 comments
Open

[BUG] bs4Dash navbarMenu() issue using Gollem #1186

HugoGit39 opened this issue Mar 7, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@HugoGit39
Copy link

HugoGit39 commented Mar 7, 2025

I have also described it in the bs4Dash github:

RinteRface/bs4Dash#389

So I love to use bs4Dash but things go wrong if i want to add header menu's as explained here:

https://bs4dash.rinterface.com/reference/navbar-menu

This code works perfectly, but not with golem.

Somehow I get the word 'navmenu' and 'left' added to the header plus dots in the left corner.

Image

library(golem)
create_golem("Test")

golem::add_module(name = "tabs")

# R/mod_tabs.R
mod_tabs_ui <- function(id) {
  ns <- NS(id)
  tabItems(.list = lapply(1:7, function(i) {
    tabItem(tabName = sprintf("Tab%s", i), sprintf("Tab %s", i))
  }))
}

mod_tabs_server <- function(id) {
  moduleServer(id, function(input, output, session) {
    # No specific server logic for tabs in this case
  })
}
# R/app_ui.R
app_ui <- function(request) {
  tagList(
    golem_add_external_resources(),
    dashboardPage(
      header = dashboardHeader(
        navbarMenu(
          id = "navmenu",
          navbarTab(tabName = "Tab1", text = "Tab 1"),
          navbarTab(tabName = "Tab2", text = "Tab 2"),
          navbarTab(
            text = "Menu",
            dropdownHeader("Dropdown header"),
            navbarTab(tabName = "Tab3", text = "Tab 3"),
            dropdownDivider(),
            navbarTab(
              text = "Sub menu",
              dropdownHeader("Another header"),
              navbarTab(tabName = "Tab4", text = "Tab 4"),
              dropdownHeader("Yet another header"),
              navbarTab(tabName = "Tab5", text = "Tab 5"),
              navbarTab(
                text = "Sub sub menu",
                navbarTab(tabName = "Tab6", text = "Tab 6"),
                navbarTab(tabName = "Tab7", text = "Tab 7")
              )
            )
          )
        )
      ),
      body = dashboardBody(mod_tabs_ui("tabs")),  # Use module here
      controlbar = dashboardControlbar(
        sliderInput(
          inputId = "controller",
          label = "Update the first tabset",
          min = 1,
          max = 4,
          value = 1
        )
      ),
      sidebar = dashboardSidebar(disable = TRUE)
    )
  )
}


# R/app_server.R
app_server <- function(input, output, session) {
  mod_tabs_server("tabs")  # Initialize module

  observeEvent(input$controller, {
    updateNavbarTabs(
      session,
      inputId = "navmenu",
      selected = paste0("Tab", input$controller)
    )
  },
  ignoreInit = TRUE
  )
}

@HugoGit39 HugoGit39 added the bug Something isn't working label Mar 7, 2025
@VincentGuyader
Copy link
Member

@ArthurData can you please have a look to that ?

@ArthurData
Copy link
Member

Hello @HugoGit39 👋

Thanks for your code — it helped me reproduce the bug! 🙏

Image

In {golem}, within the app_ui.R file, we import all the functions from {shiny} using:

#' @import shiny

So that also includes the navbarMenu() function... from {shiny}!

If you're using navbarMenu() from another package (like {bs4Dash}, for example 😛 ), make sure to call it explicitly with the namespace, e.g.:

bs4Dash::navbarMenu(...)

Your code:

bs4Dash::navbarMenu(
  id = "navmenu",
  navbarTab(tabName = "Tab1", text = "Tab 1"),
  navbarTab(tabName = "Tab2", text = "Tab 2"),
  navbarTab(
    text = "Menu",
    dropdownHeader("Dropdown header"),
    navbarTab(tabName = "Tab3", text = "Tab 3"),
    dropdownDivider(),
    navbarTab(
      text = "Sub menu",
      dropdownHeader("Another header"),
      navbarTab(tabName = "Tab4", text = "Tab 4"),
      dropdownHeader("Yet another header"),
      navbarTab(tabName = "Tab5", text = "Tab 5"),
      navbarTab(
        text = "Sub sub menu",
        navbarTab(tabName = "Tab6", text = "Tab 6"),
        navbarTab(tabName = "Tab7", text = "Tab 7")
      )
    )
  )
)

Image

Alternatively, to make things clearer and avoid potential conflicts, you could be more explicit with the functions you import, using:

#' @importFrom shiny navbarPage fluidPage ...

That way, only the functions you really need are brought into the namespace, which can help prevent this kind of issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants