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

navbarPage with title and head tag causes a ghost tab to appear #827

Closed
daattali opened this issue May 14, 2015 · 3 comments
Closed

navbarPage with title and head tag causes a ghost tab to appear #827

daattali opened this issue May 14, 2015 · 3 comments

Comments

@daattali
Copy link
Contributor

daattali commented May 14, 2015

Previous short discussion: https://groups.google.com/forum/#!topic/shiny-discuss/6C9SbSLbKmc

It seems that if I use navbarPage with a title and try to add anything to the head tag via tags$head(...), an erroneous tab appears before the first tab and it's the selected tab so it's very annoying. I'm currently getting around that by programatically setting the next tab as selected and using CSS to hide to fake tab, but a fix would be nice.

Example:

runApp(list(
  ui = navbarPage(
    "Title",
    tags$head(tags$style(HTML("body{ background: red; }"))),
    tabPanel(title = "First"),
    tabPanel(title = "Second")
  ),
  server = function(input, output, session) {}
))

Using shiny 0.11.1.9003

@daattali
Copy link
Contributor Author

For anyone who has this problem, here is my hacky fix. The first line in the server tells the first tab to be selected, and I'm adding a CSS that makes the ghost tab not appear. WATCH OUT because if you use this hack and the problem is fixed in a later shiny version, you will have to remember to remove the css hack, or else your first real tab will not appear.

runApp(list(
  ui = navbarPage(
    "Title",
    id = "page-nav",
    tags$head(tags$style(HTML(
      "#page-nav > li:first-child { display: none; }"
    ))),
    tabPanel(title = "First", "hello"),
    tabPanel(title = "Second", "world")
  ),
  server = function(input, output, session) {
    updateTabsetPanel(session, "page-nav", "First")
  }
))

@jcheng5
Copy link
Member

jcheng5 commented May 18, 2015

Why not just put the tags$head call somewhere else? navbarPage specifically only takes tabPanel objects as ... arguments (in contrast to most other container types in Shiny). You could put it at the top like this:

runApp(list(
  ui = tagList(
    tags$head(tags$style(HTML("body{ background: red; }"))),
    navbarPage(
      "Title",
      tabPanel(title = "First"),
      tabPanel(title = "Second")
    )
  ),
  server = function(input, output, session) {}
))

@jcheng5 jcheng5 closed this as completed May 18, 2015
@daattali
Copy link
Contributor Author

Thanks Joe

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