Hi Kaija,
some time ago I had the same issue with shinydashboard
(I'm not sure about the influnce of shinydashboardPlus, though). I just checked: using dashboardPagePlus
instead of dashboardPage
isn't making a difference.
I've had a short look at your code and I think the problem is, that you are calling the dashboardSidebar
(sidebar = LEFTSIDEBAR
) function outside of your UI function. For the bookmarking to work it needs to be called inside of the ui
function.
Let's have a look at the example given in the documentation.
This works (directly giving dashboardSidebar
as an argument to dashboardPage
):
library(shiny)
library(shinydashboard)
ui <- function(req) {
dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(id = "tabs",
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", icon = icon("th"), tabName = "widgets"),
menuItem("Charts", icon = icon("bar-chart-o"),
menuSubItem("Sub-item 1", tabName = "subitem1"),
menuSubItem("Sub-item 2", tabName = "subitem2")
)
)
),
dashboardBody(
bookmarkButton()
)
)
}
server <- function(input, output, session) {}
shinyApp(ui, server, enableBookmarking = "url")
This also works (dashboardSidebar
is still called inside the ui-function):
library(shiny)
library(shinydashboard)
ui <- function(req) {
sidebar <- dashboardSidebar(
sidebarMenu(id = "tabs",
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", icon = icon("th"), tabName = "widgets"),
menuItem("Charts", icon = icon("bar-chart-o"),
menuSubItem("Sub-item 1", tabName = "subitem1"),
menuSubItem("Sub-item 2", tabName = "subitem2")
)
)
)
dashboardPage(
dashboardHeader(),
sidebar = sidebar,
dashboardBody(
bookmarkButton()
)
)
}
server <- function(input, output, session) {}
shinyApp(ui, server, enableBookmarking = "url")
However, defining the dashboardSidebar
outside the of the ui function breaks the bookmarking:
library(shiny)
library(shinydashboard)
sidebar <- dashboardSidebar(
sidebarMenu(id = "tabs",
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", icon = icon("th"), tabName = "widgets"),
menuItem("Charts", icon = icon("bar-chart-o"),
menuSubItem("Sub-item 1", tabName = "subitem1"),
menuSubItem("Sub-item 2", tabName = "subitem2")
)
)
)
ui <- function(req) {
dashboardPage(
dashboardHeader(),
sidebar = sidebar,
dashboardBody(
bookmarkButton()
)
)
}
server <- function(input, output, session) {}
shinyApp(ui, server, enableBookmarking = "url")
I'm not sure why this is the case and if this is mentioned in the documentation - if not it should be updated or a GitHub issue needs to be filed.
This is mentioned in the documentation here:
If you’ve used bookmarking in a Shiny app before, you know that the UI must be wrapped in a function. The sidebarMenu()
must be called inside the UI function. It does not work to call it outside the UI function, saved the result in a variable, and then use that result in the UI function – if you do this, then the selected tab will save, but it will not restore.
I hope this helps.
Kind regards