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

Active menu_item doesn't update when using shiny.router #405

Open
thesixmax opened this issue Feb 4, 2022 · 0 comments · May be fixed by #411
Open

Active menu_item doesn't update when using shiny.router #405

thesixmax opened this issue Feb 4, 2022 · 0 comments · May be fixed by #411
Assignees

Comments

@thesixmax
Copy link

Hi! A quick question about how updating works for menu_item when also using shiny.router. My apologies if I am missing something simple. Here is a repex of a "working" dashboard:

library(shiny)
library(shiny.semantic)
library(shiny.router)

dashboard_page <- div(
  titlePanel("Dashboard"),
  p("This is a dashboard page")
)

profile_page <- div(
  titlePanel("Profile"),
  p("This is a profile page")
)

dashboard_callback <- function(input, output, session) {}
profile_callback <- function(input, output, session) {}

router <- make_router(
  route("/", dashboard_page, dashboard_callback),
  route("profile", profile_page, profile_callback)
)

ui <- semanticPage(
  menu(menu_item("Logo"),
       menu_item("Dashboard", href = route_link("/"), item_feature = "active item"),
       menu_item("Profile", href = route_link("profile")),
       class = "secondary pointing menu"
  ),
  router$ui
)

server <- function(input, output, session) {
  router$server(input, output, session)
}

shinyApp(ui, server)

It is clear that the routing is working as intended, showing the two pages when selected in the menu. However, the item feature of the selected menu_item is not updated when clicked, i.e. the "Dashboard" page is always the active menu item. I would think that the render_menu_link in menu.R should take care of this, but apparently it does not.

render_menu_link <- function(location, title, active_location = "", icon = NULL) {
  class <- if (active_location == location) "active item" else "item"
  if (is.null(icon))
    icon_ui <- ""
  else
    icon_ui <- icon(icon)
  shiny::tags$a(class = class, href = location, icon_ui, title)
}

Maybe active_location is not matching location when using shiny.router? All help is much appreciated and thanks for a great package! :-)

@ashbaldry ashbaldry linked a pull request May 3, 2022 that will close this issue
11 tasks
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

Successfully merging a pull request may close this issue.

2 participants