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

dropdownMenuOutput and sidebarMenu #229

Closed
KZARCA opened this issue Jul 7, 2017 · 8 comments
Closed

dropdownMenuOutput and sidebarMenu #229

KZARCA opened this issue Jul 7, 2017 · 8 comments

Comments

@KZARCA
Copy link

KZARCA commented Jul 7, 2017

Hi,
There is an issue resolved in the barbara/renderMenu branch, but still occurring in the master branch: when the selected tab is not the first, and the renderMenu is invalidated, the first tab gets selected. Here is an example:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(
    title = NULL,
    dropdownMenuOutput("top")
  ),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Tab1", tabName = "tab1"),
      menuItem("Tab2", tabName = "tab2")
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName = "tab1", 
              h1("tab1")
              ),
      tabItem(tabName = "tab2",
              h1("tab2"),
              textInput("foo", "Type something", "")
              )
    )
  )
)

server <- shinyServer(function(input, output, session) {
  output$top <- renderMenu({
    tags$li(class = "dropdown",
            if (input$foo == "") {
              "text1"
            } else {
              "text2"
            }
    )
  })
})

shinyApp(ui, server)

If you type something inside the textInput, tab1 is selected.

@dianalow
Copy link

I have a similar problem. My dropdownMenu:
output$messageMenu <- renderMenu({ dropdownMenu(....)})

contains reactive values, and tabs will jump back to the first tab when values are changed.

isolate stopped this problem so its probably due to reactive?

@bborgesr
Copy link
Contributor

I apologize for not being very responsive lately. This is a bit surprising (especially becausebarbara/renderMenu is behind master right now). However, I'm not currently working on this project, so unfortunately, the best answer I can give right now is to use a workaround to ensure that you stay on the current tab. See my answer to #232 for more details. I'd recommend using this workaround until I can understand the root of this issue (which I'll leave open until I start working on this package again).

@bborgesr
Copy link
Contributor

Psych! Sorry, forget my last comment... I actually ended up spending some time on this now because it was so surprising at first. Luckily, the fix was surprisingly simple (see PR for details). You should all be able to run you original workaround-less code now if you install shinydashboard from master. Let me know if there's anything not working right.

@KZARCA
Copy link
Author

KZARCA commented Jul 19, 2017

Thank you very much, it seems to work like a charm!

@shosaco
Copy link

shosaco commented Jul 27, 2017

Thank you, I updated the recent version. Just for info, the version number is not updated in the DESCRIPTION file (don't know whether that matters at all). Thanks anyways!

@bborgesr
Copy link
Contributor

bborgesr commented Sep 8, 2017

It doesn't really matter, but it should always be up to date to differentiate between the current development version (master here in Github) and the current released version (on CRAN). I've just updated it now. Thanks for the catch.

@KZARCA
Copy link
Author

KZARCA commented Sep 16, 2017

Hi,
I notice a similar behaviour with the following code when I click on the actionButton. It seems to be due to Shiny.(un)bindAll:

library(shiny)
library(shinydashboard)
library(shinyjs)

jscode <- 'shinyjs.writeABC = function(){
            Shiny.unbindAll();
            $("#foo").val("abc");
            Shiny.bindAll();
          }
      '

ui <- dashboardPage(
  dashboardHeader(
    title = NULL
  ),
  dashboardSidebar(
    sidebarMenuOutput("menuUI"),
    textInput("foo", "Type something", "")
  ),
  dashboardBody(
    useShinyjs(),
    extendShinyjs(text = jscode),
    tabItems(
      tabItem(tabName = "tab1", 
              h1("tab1")
      ),
      tabItem(tabName = "tab2",
              h1("tab2"),
              actionButton("click", "Write ABC")
      )
    )
  )
)

server <- shinyServer(function(input, output, session) {
  output$menuUI <- renderMenu({
    sidebarMenu(
      menuItem("Tab1", tabName = "tab1"),
      menuItem("Tab2", tabName = "tab2")
    )
  })
  observeEvent(input$click, {
    js$writeABC()
  })
})

shinyApp(ui, server)

@nfonsecaalves
Copy link

How can I install shinydashboard package from master?

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

5 participants