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

0.6.0 introduced minor bug #214

Closed
bborgesr opened this issue May 26, 2017 · 0 comments
Closed

0.6.0 introduced minor bug #214

bborgesr opened this issue May 26, 2017 · 0 comments
Assignees

Comments

@bborgesr
Copy link
Contributor

bborgesr commented May 26, 2017

From: https://stackoverflow.com/questions/44172064/shinydashboard-is-not-showing-item-properly-in-sidebar

For some reason, in 0.6.0, selected = TRUE in a menuItem() does not trigger the corresponding conditionalPanel(). (If you leave that out though, everything works fine - see example below).

No repro for < 0.6.0.

Repro

This works as expected:

library(shinydashboard)
library(shiny)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu(id = "tabs",
      menuItem("tab1", tabName = "tab1"),
      menuItem("tab2", tabName = "tab2")
    ),
    conditionalPanel("input.tabs == 'tab1'", 
      "This does should appear on startup"
    )
  ),
  dashboardBody()
)

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

This should result in exactly the same app, but it gets messed up:

library(shinydashboard)
library(shiny)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu(id = "tabs",
      menuItem("tab1", tabName = "tab1", selected = TRUE),
      menuItem("tab2", tabName = "tab2")
    ),
    conditionalPanel("input.tabs == 'tab1'", 
      "This should appear on startup"
    )
  ),
  dashboardBody()
)

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

Workaround

Use a dynamic sidebar menu:

library(shinydashboard)
library(shiny)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenuOutput("menu"),
    conditionalPanel("input.tabs == 'tab1'", 
      "This should appear on startup"
    )
  ),
  dashboardBody()
)

server <- function(input, output, session){
  output$menu <- renderMenu({
    sidebarMenu(id = "tabs",
      menuItem("tab1", tabName = "tab1", selected = TRUE),
      menuItem("tab2", tabName = "tab2")
    )
  })
}
shinyApp(ui, server)
bborgesr added a commit that referenced this issue May 31, 2017
…uSelectedTabItem` is always set in the body of the `ensureActivatedTab()` function
@bborgesr bborgesr self-assigned this May 31, 2017
@wch wch closed this as completed in #216 Jun 9, 2017
wch pushed a commit that referenced this issue Jun 9, 2017
* Fixes #214: make sure that the `data-value` attribute of `.sidebarMenuSelectedTabItem` is always set in the body of the `ensureActivatedTab()` function

* update NEWS

* re-organize code following a more logical structure
@wch wch removed the in progress label Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants