dashboardSidebar: Create a Boostrap 4 dashboard main sidebar

Description Usage Arguments Note Author(s) See Also Examples

Description

dashboardSidebar creates an adminLTE3 dashboard main sidebar to insert in the sidebar slot of dashboardPage.

updateSidebar toggles a dashboardSidebar on the client.

sidebarMenu creates a menu for dashboardSidebar.

menuItem creates an item to put in sidebarMenu.

menuSubItem creates an item to put in menuItem.

sidebarHeader creates a header to put in dashboardSidebar.

sidebarUserPanel creates a user Panel to put in dashboardSidebar.

updateTabItems controls the active tab of tabItems from the server. It behaves just like updateTabsetPanel.

Usage

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
bs4DashSidebar(
  ...,
  disable = FALSE,
  width = NULL,
  skin = "dark",
  status = "primary",
  elevation = 4,
  collapsed = FALSE,
  minified = TRUE,
  expandOnHover = TRUE,
  fixed = TRUE,
  id = NULL,
  customArea = NULL
)

updatebs4Sidebar(id, session = shiny::getDefaultReactiveDomain())

bs4SidebarMenu(
  ...,
  id = NULL,
  .list = NULL,
  flat = FALSE,
  compact = FALSE,
  childIndent = TRUE,
  legacy = FALSE
)

bs4SidebarMenuItem(
  text,
  ...,
  icon = NULL,
  badgeLabel = NULL,
  badgeColor = "success",
  tabName = NULL,
  href = NULL,
  newTab = TRUE,
  selected = NULL,
  expandedName = as.character(gsub("[[:space:]]", "", text)),
  startExpanded = FALSE,
  condition = NULL
)

bs4SidebarMenuSubItem(
  text,
  tabName = NULL,
  href = NULL,
  newTab = NULL,
  icon = shiny::icon("angle-double-right"),
  selected = NULL
)

bs4SidebarHeader(title)

bs4SidebarUserPanel(name, image = NULL)

updatebs4TabItems(
  session = getDefaultReactiveDomain(),
  inputId,
  selected = NULL
)

dashboardSidebar(
  ...,
  disable = FALSE,
  width = NULL,
  skin = "dark",
  status = "primary",
  elevation = 4,
  collapsed = FALSE,
  minified = TRUE,
  expandOnHover = TRUE,
  fixed = TRUE,
  id = NULL,
  customArea = NULL
)

updateSidebar(id, session = shiny::getDefaultReactiveDomain())

sidebarHeader(title)

sidebarMenu(
  ...,
  id = NULL,
  .list = NULL,
  flat = FALSE,
  compact = FALSE,
  childIndent = TRUE,
  legacy = FALSE
)

sidebarUserPanel(name, image = NULL)

menuItem(
  text,
  ...,
  icon = NULL,
  badgeLabel = NULL,
  badgeColor = "success",
  tabName = NULL,
  href = NULL,
  newTab = TRUE,
  selected = NULL,
  expandedName = as.character(gsub("[[:space:]]", "", text)),
  startExpanded = FALSE,
  condition = NULL
)

menuSubItem(
  text,
  tabName = NULL,
  href = NULL,
  newTab = NULL,
  icon = shiny::icon("angle-double-right"),
  selected = NULL
)

updateTabItems(session = getDefaultReactiveDomain(), inputId, selected = NULL)

Arguments

...

menuSubItem.

disable

If TRUE, the sidebar will be disabled.

width

The width of the sidebar. This must either be a number which specifies the width in pixels, or a string that specifies the width in CSS units.

skin

Sidebar skin. "dark" or "light".

status

Sidebar status. Valid statuses are defined as follows:

  • primary: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#007bff")}.

  • secondary: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#6c757d")}.

  • info: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#17a2b8")}.

  • success: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#28a745")}.

  • warning: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#ffc107")}.

  • danger: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#dc3545")}.

  • gray-dark: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#343a40")}.

  • gray: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#adb5bd")}.

  • white: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#fff")}.

  • indigo: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#6610f2")}.

  • lightblue: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#3c8dbc")}.

  • navy: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#001f3f")}.

  • purple: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#605ca8")}.

  • fuchsia: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#f012be")}.

  • pink: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#e83e8c")}.

  • maroon: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#d81b60")}.

  • orange: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#ff851b")}.

  • lime: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#01ff70")}.

  • teal: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#39cccc")}.

  • olive: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#3d9970")}.

elevation

Sidebar elevation. 4 by default (until 5).

collapsed

If TRUE, the sidebar will be collapsed on app startup.

minified

Whether to slightly close the sidebar but still show item icons. Default to TRUE.

expandOnHover

Whether to expand the sidebar om hover. TRUE by default.

fixed

Whether to fix the sidebar. Default to TRUE.

id

For sidebarMenu, if id is present, this id will be used for a Shiny input value, and it will report which tab is selected. For example, if id="tabs", then input$tabs will be the tabName of the currently-selected menuItem.

customArea

Sidebar bottom space area. Only works if sidebar is fixed.

session

Shiny session object.

.list

An optional list containing items to put in the menu Same as the ... arguments, but in list format. This can be useful when working with programmatically generated items.

flat

Whether sidebar items should have a flat design. FALSE by default.

compact

Whether items should be compacted. FALSE by default.

childIndent

Whether to indent children. TRUE by default.

legacy

Whether to use the old adminLTE2 item selection display. Default to FALSE.

text

Item name.

icon

An icon tag, created by icon. If NULL, don't display an icon.

badgeLabel

A label for an optional badge. Usually a number or a short word like "new".

badgeColor

A color for the badge. Valid colors:

  • primary: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#007bff")}.

  • secondary: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#6c757d")}.

  • info: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#17a2b8")}.

  • success: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#28a745")}.

  • warning: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#ffc107")}.

  • danger: \Sexpr[results=rd, stage=render]{bs4Dash:::rd_color_tag("#dc3545")}.

tabName

Should correspond exactly to the tabName given in tabItem.

href

An link address. Not compatible with tabName.

newTab

If href is supplied, should the link open in a new browser tab?

selected

If TRUE, this menuSubItem will start selected. If no item have selected=TRUE.

expandedName

A unique name given to each menuItem that serves to indicate which one (if any) is currently expanded. (This is only applicable to menuItems that have children and it is mostly only useful for bookmarking state.)

startExpanded

Whether to expand the menuItem at start.

condition

When using menuItem with conditionalPanel, write the condition here (see https://github.com/RinteRface/bs4Dash/issues/35).

title

title.

name

Name of the user.

image

A filename or URL to use for an image of the person. If it is a local file, the image should be contained under the www/ subdirectory of the application.

inputId

The id of the tabsetPanel, navlistPanel, or navbarPage object.

Note

See examples for a use case of the condition parameter.

Author(s)

David Granjon, dgranjon@ymail.com

See Also

dashboardBody

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
if (interactive()) {
  library(shiny)
  library(bs4Dash)

  shinyApp(
    ui = dashboardPage(
      header = dashboardHeader(),
      sidebar = dashboardSidebar(id = "sidebar"),
      body = dashboardBody(
        actionButton(inputId = "sidebarToggle", label = "Toggle Sidebar")
      )
    ),
    server = function(input, output, session) {
      observeEvent(input$sidebar, {
        if (input$sidebar) {
          showModal(modalDialog(
            title = "Alert",
            "The sidebar is opened.",
            easyClose = TRUE,
            footer = NULL
          ))
        }
      })

      observeEvent(input$sidebarToggle, {
        updateSidebar(id = "sidebar", session = session)
      })

      observe({
        print(input$sidebar)
      })
    }
  )
}
if (interactive()) {
  # sidebarItem with conditional value
  library(shiny)
  library(bs4Dash)

  ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar(
      sidebarMenu(
        id = "sidebarMenu",
        menuItem(
          text = "Tab 1",
          tabName = "tab1"
        ),
        menuItem(
          condition = "input.show == true",
          text = "Tab 2",
          tabName = "tab2"
        )
      )
    ),
    dashboardBody(
      tabItems(
        tabItem(
          tabName = "tab1",
          h1("Welcome!"),
          checkboxInput("show", "Show Tab 2", FALSE)
        ),
        tabItem(
          tabName = "tab2",
          h1("Hey! You found me!")
        )
      )
    )
  )
  server <- function(input, output) {}
  shinyApp(ui = ui, server = server)
}
## Only run this example in interactive R sessions
if (interactive()) {
  library(shiny)
  library(bs4Dash)

  shinyApp(
    ui = dashboardPage(
      header = dashboardHeader(skin = "dark"),
      body = dashboardBody(
        tabItems(
          tabItem(
            tabName = "tab1",
            sliderInput("obs", "Number of observations:",
              min = 0, max = 1000, value = 500
            ),
            plotOutput("distPlot")
          ),
          tabItem(
            tabName = "tab2",
            checkboxGroupInput(
              "variable", "Variables to show:",
              c(
                "Cylinders" = "cyl",
                "Transmission" = "am",
                "Gears" = "gear"
              )
            ),
            tableOutput("data")
          ),
          tabItem(
            tabName = "tab3",
            checkboxInput("val", "Some value", FALSE),
            textOutput("value")
          ),
          tabItem(
            tabName = "tab4",
            "Nothing special here!"
          ),
          tabItem(
            tabName = "tab5",
            "Tab 5"
          ),
          tabItem(
            tabName = "tab6",
            "Tab 6"
          ),
          tabItem(
            tabName = "tab7",
            "Tab 7"
          )
        )
      ),
      sidebar = dashboardSidebar(
        skin = "light",
        inputId = "sidebarState",
        sidebarMenu(
          id = "sidebar",
          menuItem(
            text = "Tab 1",
            tabName = "tab1",
            icon = icon("shuttle-van")
          ),
          menuItem(
            text = "Tab 2",
            tabName = "tab2",
            icon = icon("space-shuttle"),
            selected = TRUE
          ),
          menuItem(
            text = "Item List 1",
            icon = icon("bars"),
            startExpanded = TRUE,
            menuSubItem(
              text = "Item 3",
              tabName = "tab3",
              icon = icon("circle-thin")
            ),
            menuSubItem(
              text = "Item 4",
              tabName = "tab4",
              icon = icon("circle-thin")
            )
          ),
          menuItem(
            text = "Item List 2",
            icon = icon("bars"),
            startExpanded = FALSE,
            menuSubItem(
              text = "Item 5",
              tabName = "tab5",
              icon = icon("circle-thin")
            ),
            menuSubItem(
              text = "Item 6",
              tabName = "tab6",
              icon = icon("circle-thin")
            )
          ),
          menuItem(
            text = "Tab 7",
            tabName = "tab7",
            icon = icon("home")
          )
        )
      ),
      controlbar = dashboardControlbar(
        skin = "light",
        sliderInput(
          inputId = "controller",
          label = "Update the first tabset",
          min = 1,
          max = 6,
          value = 2
        )
      ),
      footer = bs4DashFooter()
    ),
    server = function(input, output, session) {
      observe(print(input$sidebarItemExpanded))
      observe(print(input$sidebar))

      # update tabset1
      observeEvent(input$controller,
        {
          updateTabItems(
            session,
            inputId = "sidebar",
            selected = paste0("tab", input$controller)
          )
        },
        ignoreInit = TRUE
      )

      output$distPlot <- renderPlot({
        hist(rnorm(input$obs))
      })

      output$data <- renderTable(
        {
          mtcars[, c("mpg", input$variable), drop = FALSE]
        },
        rownames = TRUE
      )

      output$value <- renderText({
        input$val
      })
    }
  )
}

bs4Dash documentation built on July 23, 2021, 5:06 p.m.