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

menuItem [[: subscript out of bounds error #351

Open
ugurdar opened this issue Jun 17, 2023 · 4 comments
Open

menuItem [[: subscript out of bounds error #351

ugurdar opened this issue Jun 17, 2023 · 4 comments
Labels
question Further information is requested

Comments

@ugurdar
Copy link

ugurdar commented Jun 17, 2023

Hi there,

When I used old version (2.2.1) I haven't got this error but when I updated the package this error has occured.

Warning: Error in [[: subscript out of bounds
  80: <Anonymous>
  79: menuItem
  71: home_page$ui 

When I use this it's working.

remove.packages("bs4Dash")
packageurl <- "https://cran.r-project.org/src/contrib/Archive/bs4Dash/bs4Dash_2.2.1.tar.gz"
install.packages(packageurl, repos=NULL, type="source")

My sidebar function is:

sidebar = dashboardSidebar(
      minified = TRUE,
      sidebarMenu(id = ns('tabs'),
                  menuItem('Bank Deep Dive', tabName = 'bank_deep_dive',
                           icon = NULL,# Icon can added
                           selected = TRUE,
                           menuItem('Bank Information',
                                    tabName = 'bank_info'
                           ),
                           menuItem('Assets & Liabilities',
                                    tabName = 'assets_liabilities'
                           ),
                           menuItem('Income & Expense',
                                    tabName = 'income_expense'),
                           menuItem('Additional Schedules',
                                    tabName = 'additional_schedules'),
                           menuItem('Demographics',
                                    tabName = 'demographics'),
                           menuItem('Branch Network',
                                    tabName = 'branch_network'),
                           menuItem('Performance & Condition',
                                    tabName = 'performance_condition'),
                           menuItem('Credit Quality',
                                    tabName = 'credit_qualities'),
                           menuItem('Contacts',
                                    tabName = 'contacts_bankdeepdive')
                  ),
                  menuItem('Bank Comparison', tabName = 'bank_comparison',
                           icon = NULL),

                  menuItem('Bank Ranking', tabName = 'bank_ranking',
                           menuItem('Deposit Utilization ',
                                    tabName = 'deposit_util'),
                           menuItem('Deposit Composition',
                                    tabName = 'deposit_comp'),
                           menuItem('Net Interest Margin',
                                    tabName = 'ranking_nim'),


                           menuItem('Deposit Efficiency',
                                    tabName = 'deposit_eff'),
                           menuItem('Banks/Call Reports', tabName = 'bankcall_rep',
                                    menuSubItem('First Mortgages',
                                                tabName = 'first_mort',
                                                icon = NULL),
                                    menuSubItem('Home Equity Loans',
                                                tabName = 'home_eq',
                                                icon = NULL),
                                    menuSubItem('Credit Card Portfolios',
                                                tabName = 'creditcard_port',
                                                icon = NULL),
                                    menuSubItem('Adjusted Nonperforming Loan Ratios',
                                                tabName = 'nonper_ratio',
                                                icon = NULL),
                                    menuSubItem('Noninterest Income Ratio',
                                                tabName = 'nonint_inc',
                                                icon = NULL),
                                    menuSubItem('Largest C&I Loans',
                                                tabName = 'ci_loans',
                                                icon = NULL),
                                    menuSubItem('Return on Average Assets',
                                                tabName = 'roa',
                                                icon = NULL),
                                    menuSubItem('Return on Average Equity',
                                                tabName = 'roe',
                                                icon = NULL),
                                    menuSubItem('Net Income to Salary and Benefits',
                                                tabName = 'netinc_salary',
                                                icon = NULL),
                                    menuSubItem('Largest Portfolios of Loans and Leases',
                                                tabName = 'lnl_port',
                                                icon = NULL),
                                    menuSubItem('Most Assets',
                                                tabName = 'most_assets',
                                                icon = NULL),
                                    menuSubItem('Most Deposits',
                                                tabName = 'most_deposits',
                                                icon = NULL),
                                    menuSubItem('Securities',
                                                tabName = 'securities',
                                                icon = NULL),
                                    menuSubItem('Largest Portfolios of Mortgage-Backed Securities',
                                                tabName = 'mbs',
                                                icon = NULL)
                           ),


                           menuItem('Bank Holding Company Financials', tabName = 'bankhold',
                                    icon = NULL,
                                    menuSubItem('Credit Card Loans Portfolios',
                                                tabName = 'creditcard_loan',
                                                icon = NULL),
                                    menuSubItem('Business Loan Portfolios',
                                                tabName = 'bus_loan',
                                                icon = NULL),
                                    menuSubItem('Consumer Loan Portfolios',
                                                tabName = 'cons_loan',
                                                icon = NULL),
                                    menuSubItem('Loan/Deposit Ratios Among Bank Holding Companies',
                                                tabName = 'ldr',
                                                icon = NULL),
                                    menuSubItem('Largest Commercial Real Estate Loan Portfolios',
                                                tabName = 're_loans',
                                                icon = NULL),
                                    menuSubItem('Most Employees',
                                                tabName = 'num_emp',
                                                icon = NULL),
                                    menuSubItem('Most Efficient Bank Holding Companies',
                                                tabName = 'efficient',
                                                icon = NULL),
                                    menuSubItem('Small-Business Loan Balances',
                                                tabName = 'small_bus',
                                                icon = NULL),
                                    menuSubItem('Most Profitable Banks',
                                                tabName = 'profitable',
                                                icon = NULL)

                           )
                  ),

                  menuItem('U.S. Banks Macro View', tabName = 'macroviews',
                           icon = NULL,
                           menuSubItem('Summary Balance Sheet & Income Statement',
                                      tabName = 'sum_tab',
                                      icon = NULL),
                           menuSubItem('Frequency Table',
                                       tabName = 'freq_tab',
                                       icon = NULL),
                           menuSubItem('Summary Bar',
                                      tabName = 'sum_graph',
                                      icon = NULL),
                           menuSubItem('Summary Line',
                                       tabName = 'sum_linegraph',
                                       icon = NULL),
                           menuSubItem('Core Deposit',
                                      tabName = 'coredep',
                                      icon = NULL)

                  ),
                  menuItem('Modeling and Analytics', tabName = 'modeling',
                           icon = NULL)
                )
    ),

When I commented this part it's also working but I didn't understand where it comes from.

 menuItem('Bank Holding Company Financials', tabName = 'bankhold',
                                    icon = NULL,
                                    menuSubItem('Credit Card Loans Portfolios',
                                                tabName = 'creditcard_loan',
                                                icon = NULL),
                                    menuSubItem('Business Loan Portfolios',
                                                tabName = 'bus_loan',
                                                icon = NULL),
                                    menuSubItem('Consumer Loan Portfolios',
                                                tabName = 'cons_loan',
                                                icon = NULL),
                                    menuSubItem('Loan/Deposit Ratios Among Bank Holding Companies',
                                                tabName = 'ldr',
                                                icon = NULL),
                                    menuSubItem('Largest Commercial Real Estate Loan Portfolios',
                                                tabName = 're_loans',
                                                icon = NULL),
                                    menuSubItem('Most Employees',
                                                tabName = 'num_emp',
                                                icon = NULL),
                                    menuSubItem('Most Efficient Bank Holding Companies',
                                                tabName = 'efficient',
                                                icon = NULL),
                                    menuSubItem('Small-Business Loan Balances',
                                                tabName = 'small_bus',
                                                icon = NULL),
                                    menuSubItem('Most Profitable Banks',
                                                tabName = 'profitable',
                                                icon = NULL)

                           )
@DivadNojnarg DivadNojnarg added the question Further information is requested label Jun 20, 2023
@DivadNojnarg
Copy link
Member

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

@archymedes
Copy link

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'))
    )
  )
)

@alearrigo
Copy link

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.

@ugurdar
Copy link
Author

ugurdar commented Oct 20, 2023

I'm still using version 2.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants