Git Product home page Git Product logo

Comments (4)

DivadNojnarg avatar DivadNojnarg commented on June 3, 2024

Hi,

Like for {shinydashboard}, the menuItem() function has been thought to accept menuSubItem(). In the above example, sometimes, you pass in other menuItem() which likely fails.

From a practical point of view, do you need all these menus? This seems to be a lot from a UX perspective and I am afraid end users can get lost. I would perhaps merge few items together and create sub-sections directly in the dashboard body.

As another alternative, {bs4Dash} 2.3.0 (CRAN) supports navbar menus with unlimited nested structure:

library(shiny)
 library(bs4Dash)
 
 tabs <- tabItems(.list = lapply(1:7, function(i) {
  tabItem(tabName = sprintf("Tab%s", i), sprintf("Tab %s", i))
 }))
 
 shinyApp(
   ui = 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(tabs),
     controlbar = dashboardControlbar(
       sliderInput(
         inputId = "controller",
         label = "Update the first tabset",
         min = 1,
         max = 4,
         value = 1
       )
     ),
     sidebar = dashboardSidebar(disable = TRUE)
   ),
   server = function(input, output, session) {
     observeEvent(input$controller, {
       updateNavbarTabs(
         session,
         inputId = "navmenu",
         selected = paste0("Tab", input$controller)
       )
     },
     ignoreInit = TRUE
     )
   }
 )
Screenshot 2023-06-20 at 17 13 56

from bs4dash.

archymedes avatar archymedes commented on June 3, 2024

Any news about the old behaviour where menuItem accepted other menuItems?
I have not a so complicated sidebar as the first example but looks better than using navbar

sidebarMenu(
  id      = 'sidebarmenu',
  flat    = FALSE,
  compact = TRUE,
  legacy  = FALSE,
  menuItem(tabName = 'about', text = 'About', icon = icon('circle-info')),
  menuItem(
    text = 'My apps',
    icon = icon('bars'),
    menuItem(
      text = 'App 1',
      icon = icon('arrow-right'),
      menuSubItem(tabName = 'app1-1', text = 'App 1-1', icon = icon('arrow-right')),
      menuSubItem(tabName = 'app1-2', text = 'App 1-2', icon = icon('arrow-right')),
      menuSubItem(tabName = 'app1-3', text = 'App 1-3', icon = icon('arrow-right'))
    ),
    menuItem(
      text = 'App 2',
      icon = icon('arrow-right'),
      menuSubItem(tabName = 'app2-1', text = 'App 2-1', icon = icon('arrow-right')),
      menuSubItem(tabName = 'app2-2', text = 'App 2-2', icon = icon('arrow-right')),
      menuSubItem(tabName = 'app2-3', text = 'App 2-3', icon = icon('arrow-right'))
    )
  )
)

from bs4dash.

alearrigo avatar alearrigo commented on June 3, 2024

Same problem here:


library(shiny)
library(bs4Dash)

# UI ----------------------------------------------------------------------

ui <- dashboardPage(
  #dark = T,
  header = dashboardHeader(title = "Test Shiny"),
  sidebar = dashboardSidebar(
    inputId = "sidebarState",
    skin = "dark",
    sidebarMenu(
      id = "sidebar",
      menuItem(text = "Home",tabName = "home"),
      menuItem(text = "CDG", tabName = "cdg",
               menuItem(text = "Variabili Produttive",tabName = "VP",
                       menuItem(text = "VP Domanda",tabName = "vp_domanda",
                                menuSubItem(text = "a",tabName = "vp_domanda_a"),
                                menuSubItem(text = "b",tabName = "vp_domanda_b"),
                                menuSubItem(text = "c",tabName = "vp_domanda_c")),
                       menuItem(text = "VP Offerta",tabName = "vp_offerta")),
               menuItem(text = "Indicatori",tabName = "indic"))
    )
  ),

  body = dashboardBody()
)

# Server ------------------------------------------------------------------


server <-  function(input, output) { 
  
  }



# Run App -----------------------------------------------------------------


# Run the application 
shinyApp(ui = ui, server = server)


Error in subItems[[i]] : subscript out of bounds

The catch is that if I run the same code with shinydashboard instead of bs4Dash it runs flawlessly.

from bs4dash.

ugurdar avatar ugurdar commented on June 3, 2024

I'm still using version 2.2.1

from bs4dash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.