When a bookmarked shinydashboard with multiple tabs is loaded, the previously active tab should be active again on load - i.e., if the dashboard has 2 tabs and the bookmark button is on tab 2, tab 2 should be active when the bookmark is loaded. This works correctly if both tabs were created in the ui.
However, if tab 2 was created on the server side via renderMenu, when the bookmark is loaded tab 1 is active instead of tab 2.
The example below shows this behavior. If you move the bookmark to tab 3, it will work correctly.
library(shiny)
library(shinydashboard)
enableBookmarking(store = "server")
ui <- function(request){
dashboardPage(
dashboardHeader(title = "demo"),
dashboardSidebar(
sidebarMenu(id="sidebar",
menuItem("Static 1", tabName = "static1"),
sidebarMenuOutput("menu"),
menuItem("Static 2", tabName = "static2")
)
),
dashboardBody(
tabItems(
tabItem(tabName="static1", h2("something1")),
tabItem(tabName="dynamic", h2("something2"), bookmarkButton()),
tabItem(tabName="static2", h2("something3"))
)
)
)
}
server <- function(input, output) {
output$menu <- renderMenu({
sidebarMenu(
menuItem("Dynamic", tabName="dynamic")
)
})
}
shinyApp(ui = ui, server = server)
I expect that a bookmark should load the active tab regardless of whether the tab was created in the ui or rendered by the server.
Edit - I tried passing the sidebarMenu id to the server as well, but that didn't work:
server <- function(input, output) {
output$menu <- renderMenu({
sidebarMenu(id="sidebar",
menuItem("Dynamic", tabName="dynamic")
)
})
}