Opening multiple sidebar Items causes reloading-failure in renderUI / uiOutput (?)

Hello !

The code below creates a Sidebar with TabItems; those again contain Subtabs which will eventually address some ouput in the mainBody when clicked.

My problem is that when e.g. TAB3 is open and I click to open TAB1 (or TAB2) without closing TAB3, then TAB3 will not load anymore (it does open though, as seen by the subItem icon >>)

I use renderUI and uiOutput to accomplish this and I use "do.call" to set up the submenus...

I already tried changing menuItem to menuSubItem etc. ... that does not seem to do the trick. Is this "normal behaviour" or am I missing something (?)

Do you always have to close a Tab before opening another one?

Any help is appreciated of course!

Thanks, gregor

library(shiny)
library(shinydashboard)
## set up a main body... no content needed
body <- dashboardBody( title="Title" )
## set up a sidebar with TABS containing subTABS
## the subTABS are adressed via an uiOutput() 
sidebar <- dashboardSidebar (
  ##
  sidebarMenu(
    menuItem("TAB1",menuSubItem(uiOutput("Sidebar_sub1")) ),
    menuItem("TAB2",menuSubItem(uiOutput("Sidebar_sub2"))  ),
    menuItem("TAB3",menuSubItem(uiOutput("Sidebar_sub3"))  ) )
) 
##
server <- function(input, output) {
  ## starting parameters
  nsubtabs    <- 9
  tabnames <- paste0("subtab",1:nsubtabs)
  ## set up a list for all subtabs
  Menus_sub <- vector("list", nsubtabs)
  for(i in 1:nsubtabs) {
    Menus_sub[[i]] <- menuSubItem(tabnames[i], tabName = tabnames[i]) }
  ## use renderUI to create sidebar-output
  output$Sidebar_sub1 <- renderUI({  
    do.call(function(...) sidebarMenu(id = "sidebarMenu_sub1", ...), Menus_sub[1:3])
  })
  ##
  output$Sidebar_sub2 <- renderUI({  
    do.call(function(...) sidebarMenu(id = "sidebarMenu_sub2", ...), Menus_sub[4:6])
  })
  ##
  output$Sidebar_sub3 <- renderUI({  
    do.call(function(...) sidebarMenu(id = "sidebarMenu_sub3", ...), Menus_sub[7:9])
  })
  ##
}
##
ui <- dashboardPage(dashboardHeader(title = "Title2"), sidebar,body)
##
shinyApp(ui, server)

Hi there,

I found a solution: replace the uiOutput() in the sidebarMenu() with dropdownMenuOutput(), such as:

sidebar <- dashboardSidebar (
  ##
  sidebarMenu(
    menuItem("TAB1",menuSubItem(dropdownMenuOutput("Sidebar_sub1")) ),
    menuItem("TAB2",menuSubItem(dropdownMenuOutput("Sidebar_sub2"))  ),
    menuItem("TAB3",menuSubItem(dropdownMenuOutput("Sidebar_sub3"))  ) )
) 

It seems like after that change, the menus that are created dynamically are fit into the dropdown, instaed of going into separate menuItems. All good now!

Thanks,
gregor

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.