tabsetPanel: Create a tabsetPanel

Description Usage Arguments Author(s) Examples

View source: R/tabs.R

Description

Imported by bs4TabCard but can be used alone. This is a modified shiny::tabsetPanel, to handle bootstrap 4. This function will be upgraded starting from shiny 1.7.0 (support Bootstrap 4 tabs).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
tabsetPanel(
  ...,
  id = NULL,
  selected = NULL,
  type = c("tabs", "pills"),
  position = NULL,
  vertical = FALSE,
  side = "left",
  .list = NULL
)

Arguments

...

tabPanel() elements to include in the tabset

id

If provided, you can use input$id in your server logic to determine which of the current tabs is active. The value will correspond to the value argument that is passed to tabPanel().

selected

The value (or, if none was supplied, the title) of the tab that should be selected by default. If NULL, the first tab will be selected.

type
'"tabs"'

Standard tab look

'"pills"'

Selected tabs use the background fill color

position

This argument is deprecated; it has been discontinued in Bootstrap 3.

vertical

Whether to displays tabs vertically. Default to FALSE.

side

Tabs side: "left" or "right".

.list

In case of programmatically generated items. See example.

Author(s)

David Granjon, dgranjon@ymail.com

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
if(interactive()){
 library(shiny)
 library(bs4Dash)

 shinyApp(
   ui = dashboardPage(
    header = dashboardHeader(),
    sidebar = dashboardSidebar(),
    controlbar = dashboardControlbar(),
    footer = dashboardFooter(),
    title = "Bootstrap 4 tabsetPanel",
    body = dashboardBody(
     # manually inserted panels
     tabsetPanel(
      id = "tabcard",
      tabPanel(
       title = "Tab 1", 
       "Content 1"
      ),
      tabPanel(
       title = "Tab 2", 
       "Content 2"
      ),
      tabPanel(
       title = "Tab 3", 
       "Content 3"
      )
     ),
     
     br(), br(),
     # programmatically inserted panels
     tabsetPanel(
       id = "tabset",
       .list = lapply(1:3, function(i) {
         tabPanel(
           title = paste0("Tab", i), 
           active = FALSE,
           paste("Content", i)
         )
       })
      )
    )
   ),
   server = function(input, output) {}
 )
 
 # update tabsetPanel
 shinyApp(
  ui = dashboardPage(
   title = "updateTabsetPanel",
   header = dashboardHeader(),
   body = dashboardBody(
     tabsetPanel(
       id = "tabset1",
       selected = "Tab 2",
       tabPanel(
         title = "Tab 1", 
         numericInput("val", "Value:", 10, min = 1, max = 100),
         verbatimTextOutput("value")
       ),
       tabPanel(
         title = "Tab 2", 
         "Content 2"
       ),
       tabPanel(
         title = "Tab 3", 
         checkboxGroupInput(
           inline = TRUE,
           "variable", "Variables to show:",
           c("Cylinders" = "cyl",
             "Transmission" = "am",
             "Gears" = "gear")
         ),
         tableOutput("data")
       )
     ),
     uiOutput("tabSetPanel2")
   ),
   sidebar = dashboardSidebar(
     skin = "light",
     sliderInput(
       inputId = "controller",
       label = "Update the first tabset",
       min = 1,
       max = 3,
       value = 2
     ),
     br(),
     sliderInput(
       inputId = "controller2",
       label = "Update the second tabset",
       min = 1,
       max = 3,
       value = 3
     )
   ),
   controlbar = dashboardControlbar(collapsed = FALSE),
   footer = dashboardFooter()
 ),
 server = function(input, output, session) {
 
   output$tabSetPanel2 <- renderUI({
    tabsetPanel(
      id = "tabset2",
      tabPanel(
        title = "Tab 1", 
        p("Tab 1 ")
      ),
      tabPanel(
        title = "Tab 2", 
        p("Tab 2")
      ),
      tabPanel(
        title = "Tab 3", 
        p("Tab 3")
      )
    )
   })
   
   # update tabset1
   observeEvent(input$controller, {
     updateTabsetPanel(
       session, 
       inputId = "tabset1", 
       selected = paste("Tab", input$controller)
     )
   }, ignoreInit = TRUE)
   
   # update tabset 2
   observeEvent(input$controller2, {
     updateTabsetPanel(
       session, 
       inputId = "tabset2", 
       selected = paste("Tab", input$controller2)
     )
   }, ignoreInit = TRUE)
   
   output$distPlot <- renderPlot({
     hist(rnorm(input$obs))
   })
   
   output$data <- renderTable({
     mtcars[, c("mpg", input$variable), drop = FALSE]
   }, rownames = TRUE)
   
   output$txt <- renderText({
     paste("You chose", input$rb)
   })
   
   output$value <- renderText({ input$val })
   
  }
 )
}

hiplot/bs4Dash2 documentation built on Dec. 20, 2021, 3:51 p.m.