Shinydashboard supports all the normal interactive functionality that Shiny does. If you need a refresher on all the interactive capabilities of Shiny (through inputs, outputs, reactives, etc), take a look at our website’s articles.
In addition to all the normal Shiny inputs and outputs that can be present in a shinydashboard app, there are a few things that are specific to the structure of such apps. In particular, most shinydashboard apps have a sidebar. As of the 0.6 shinydashboard release, app authors can access the entire state of the sidebar as Shiny inputs. There are up to three inputs that can be generated if you have a sidebar in your app. (However, it should be noted that two these are not “normal” inputs, since they are generated automatically and have a fixed name – rather than you, as the app author, deciding that name.)
Let’s get into the details. The three sidebar-related inputs allow you to:
As alluded in the previous sections, the features added in shinydashboard 0.6 allow it to integrate a lot better with bookmarkable state, since the state of the sidebar will be automatically bookmarked. For example, the app below does not specify any explicit inputs (like textInput
or sliderInput
), but the state of the sidebar is automatically bookmarked (you can see this in the URL once you click “Bookmark…”). The app below combines all three inputs described before. You can use it to experiment with:
menuItem()
/ menuSubItem()
(and see the value of input$tabs
also change);menuItem()
(and see the value of input$sidebarItemExpanded
also change);input$sidebarCollapsed
also change).app.R
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")