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

Sidebar menu with dynamic content does not show default tab #71

Closed
maelick opened this issue Jul 20, 2015 · 9 comments
Closed

Sidebar menu with dynamic content does not show default tab #71

maelick opened this issue Jul 20, 2015 · 9 comments
Assignees

Comments

@maelick
Copy link

maelick commented Jul 20, 2015

When using a sidebar menu dynamically generated no tab is shown by default.

Here's the example from the doc with some text added inside the dashboard bod to be able to replicate the issue:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Dynamic sidebar"),
  dashboardSidebar(
    sidebarMenuOutput("menu")
  ),
  dashboardBody(tabItems(
    tabItem(tabName = "dashboard", h2("Dashboard tab content"))
  ))
)

server <- function(input, output) {
  output$menu <- renderMenu({
    sidebarMenu(id="mytabs",
      menuItem("Menu item", tabName="dashboard", icon = icon("calendar"))
    )
  })
}

shinyApp(ui, server)

By default it does not show the tab item "dashboard" and the user has to clic on it to show it. I tried to manually fix this in my app using updateTabItems but it does not work either because the sidebar menu object is not stored in the input variable (but it was in the static version).

I tested this both with the CRAN and last Github versions of shiny and shinydashboard.

@tfrojd
Copy link

tfrojd commented Sep 16, 2015

Same issue here.

@ChanningWong
Copy link

The same problem occured

@danwwilson
Copy link

It would be great to get a solution to this. I've also posted to stack overflow with no response yet

@glfeng318
Copy link

Same issue here. when this issue will be fixed?

@isaacfab
Copy link

This is still not fixed.. but here is a simple work around if your default page is static or can be pre-built without reactivity. You can list multiple sidebarMenu Items in a row.

library(shiny)
library(shiny dashboard

ui <- dashboardPage(
  dashboardHeader(title = "Dynamic sidebar"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Default Menu item", tabName="intro_page", icon = icon("info"))
    ),
    sidebarMenuOutput("menu")
  ),
  dashboardBody(tabItems(
      tabItem(tabName = "intro_page",
              fluidRow(box(helpText("Here is your default page!"),width=12))
      ),
      tabItem(tabName = "dashboard", h2("Dashboard tab content"))
  )
  )
)

server <- function(input, output) {
  output$menu <- renderMenu({
    sidebarMenu(id="myths",)
                menuItem("Menu item", tabName="dashboard", icon = icon("calendar"))
    )
  })
}

shinyApp(ui, server)

@sbstern
Copy link

sbstern commented Apr 29, 2016

Bump on this. It makes shinydashboard almost unusable for what I am trying to do...

@glfeng318
Copy link

i used shinyjs for a temporary fix
shinyjs.initPage = function(){setTimeout(function(){$("#sidebarmenu > li:nth-child(1) > a").click();}, 1500);}

@mayeromain
Copy link

mayeromain commented May 10, 2016

Here is a solution using updateTabItems.
You can also find it on stackoverflow.

library(shiny)
library(shinydashboard)
ui <- dashboardPage(
  dashboardHeader(title = "Dynamic sidebar"),
  dashboardSidebar(
    sidebarMenu(id="tabs",
    sidebarMenuOutput("menu")
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName = "m1", p("Menu content 1") ),
      tabItem(tabName = "m2", p("Menu content 2") )
    )
  )
)
server <- function(input, output,session) {

  output$menu <- renderMenu({
    sidebarMenu(
           menuItem("Menu item1", tabName="m1", icon = icon("calendar")),
           menuItem("Menu item2", tabName="m2", icon = icon("database"))
           )
  })
  isolate({updateTabItems(session, "tabs", "m2")})
}
shinyApp(ui, server)

With multiple tabs
http://stackoverflow.com/questions/36742932/r-shinydashboard-dynamic-menu-selection/36913826#36913826

Or simpler here
http://stackoverflow.com/questions/37033601/dynamic-sidebar-menu-rshiny/37133748#37133748

@wch wch added the targeted label Jan 26, 2017
bborgesr added a commit that referenced this issue Feb 24, 2017
…led. This allows for the correct tab to be selected for dynamic sidebars (closes #87, closes #71)
@bborgesr bborgesr self-assigned this Feb 24, 2017
@bborgesr bborgesr mentioned this issue Apr 25, 2017
@bborgesr
Copy link
Contributor

Fixed in #199

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants