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

Dynamic menuSubItems with apply() adds some extra text #306

Closed
shahreyar-abeer opened this issue Sep 11, 2022 · 2 comments
Closed

Dynamic menuSubItems with apply() adds some extra text #306

shahreyar-abeer opened this issue Sep 11, 2022 · 2 comments
Labels
fixed-in-dev Fixed in development version

Comments

@shahreyar-abeer
Copy link

Code
menus = data.frame(
  names = c("menu1", "menu2")
)

sub_menus = data.frame(
  names = c("sub1", "sub2")
)

library(shiny)
library(bs4Dash)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    skin = "light",
    sidebarMenu(
      apply(menus, 1, function(menu) {
        menuItem(
          text = menu["names"],
          icon = icon("bars"),
          
          apply(sub_menus, 1, function(sub) {
            
            menuSubItem(
              text = sub['names'],
              icon = icon('chevron-right')
            )
          })
        )
      })

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

This code produces the following app.
There an additional 'treeview-link' text below the subItems

image

@shahreyar-abeer shahreyar-abeer changed the title Dynamic menuSubItems with apply adds something extra Dynamic menuSubItems with apply adds some extra text Sep 11, 2022
@shahreyar-abeer shahreyar-abeer changed the title Dynamic menuSubItems with apply adds some extra text Dynamic menuSubItems with apply() adds some extra text Sep 11, 2022
DivadNojnarg added a commit that referenced this issue Oct 1, 2022
@DivadNojnarg
Copy link
Member

I pushed a fix. Please download bs4Dash on the dev branch and use lists:

subitems <- lapply(1:5, function(i) {
    menuSubItem(text = i)
})

items <- lapply(1:2, function(i) {
    menuItem(
        text = i, 
        tabName = i,
        .list = if (i == 2) subitems,
        icon = icon("folder-open"))
})

library(shiny)
library(bs4Dash)

ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar(
        skin = "light",
        sidebarMenu(.list = items)
    ),
    dashboardBody(
        tabItems(
            tabItem(tabName = 1, "Tab 1"),
            tabItem(tabName = 2, "Tab 2")
        )
    )
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server)

@DivadNojnarg DivadNojnarg added the fixed-in-dev Fixed in development version label Oct 1, 2022
@shahreyar-abeer
Copy link
Author

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed-in-dev Fixed in development version
Projects
None yet
Development

No branches or pull requests

2 participants