updatebs4TabItems: Change the selected sidebar tab on the client

Description Usage Arguments Examples

Description

This function controls the active tab of bs4TabItems from the server. It behaves just like updatebs4TabSetPanel.

Usage

1
2
3
updatebs4TabItems(session, inputId, selected = NULL)

updateTabItems(session, inputId, selected = NULL)

Arguments

session

shiny session.

inputId

bs4TabSetPanel unique id.

selected

the tab to be selected.

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
## Only run this example in interactive R sessions
if (interactive()) {
 library(shiny)
 library(bs4Dash)
 
 shinyApp(
   ui = bs4DashPage(
     sidebar_collapsed = FALSE,
     controlbar_collapsed = TRUE,
     enable_preloader = FALSE,
     navbar = bs4DashNavbar(skin = "dark"),
     body = bs4DashBody(
       bs4TabItems(
         bs4TabItem(
           tabName = "tab1",
           sliderInput("obs", "Number of observations:",
                       min = 0, max = 1000, value = 500
           ),
           plotOutput("distPlot")
         ),
         bs4TabItem(
           tabName = "tab2",
           checkboxGroupInput("variable", "Variables to show:",
                              c("Cylinders" = "cyl",
                                "Transmission" = "am",
                                "Gears" = "gear")),
           tableOutput("data")
         ),
         bs4TabItem(
           tabName = "tab3",
           checkboxInput("val", "Some value", FALSE),
           textOutput("value")
         ),
         bs4TabItem(
           tabName = "tab4",
           "Nothing special here!"
         ),
         bs4TabItem(
           tabName = "tab5",
           "Tab 5"
         ),
         bs4TabItem(
           tabName = "tab6",
           "Tab 6"
         ),
         bs4TabItem(
           tabName = "tab7",
           "Tab 7"
         )
       )
     ),
     sidebar = bs4DashSidebar(
       skin = "light",
       inputId = "sidebarState",
       bs4SidebarMenu(
         id = "sidebar",
         bs4SidebarMenuItem(
           text = "Tab 1",
           tabName = "tab1",
           icon = "shuttle-van"
         ),
         bs4SidebarMenuItem(
           text = "Tab 2",
           tabName = "tab2",
           icon = "space-shuttle",
           selected = TRUE
         ),
         bs4SidebarMenuItem(
           text = "Item List 1",
           icon = "bars",
           startExpanded = TRUE,
           bs4SidebarMenuSubItem(
             text = "Item 3",
             tabName = "tab3",
             icon = "circle-thin"
           ),
           bs4SidebarMenuSubItem(
             text = "Item 4",
             tabName = "tab4",
             icon = "circle-thin"
           )
         ),
         bs4SidebarMenuItem(
           text = "Item List 2",
           icon = "bars",
           startExpanded = FALSE,
           bs4SidebarMenuSubItem(
             text = "Item 5",
             tabName = "tab5",
             icon = "circle-thin"
           ),
           bs4SidebarMenuSubItem(
             text = "Item 6",
             tabName = "tab6",
             icon = "circle-thin"
           )
         ),
         bs4SidebarMenuItem(
           text = "Tab 7",
           tabName = "tab7",
           icon = "home"
         )
       )
     ),
     controlbar = bs4DashControlbar(
       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, {
       updatebs4TabItems(
         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 })
     
   }
 )
}

RX-PBB/bs4Mash documentation built on April 11, 2020, 12:15 a.m.