bs4InsertTab: Insert a bs4TabPanel in a bs4TabSetPanel

Description Usage Arguments Examples

View source: R/update-functions.R

Description

Insert a bs4TabPanel in a bs4TabSetPanel

Usage

1
2
3
4
5
6
7
8
bs4InsertTab(
  inputId,
  tab,
  target,
  position = c("before", "after"),
  select = FALSE,
  session = shiny::getDefaultReactiveDomain()
)

Arguments

inputId

bs4TabSetPanel id.

tab

bs4TabPanel to insert.

target

bs4TabPanel after of before which the new tab will be inserted.

position

Insert before or after: c("before", "after").

select

Whether to select the newly inserted tab. FALSE by default.

session

Shiny session object.

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
if (interactive()) {
 library(shiny)
 library(bs4Dash)
 
 ui <-  bs4DashPage(
   sidebar_collapsed = T,
   sidebar = bs4DashSidebar(),
   bs4DashFooter(),
   body = bs4DashBody(
     actionButton("add1","ADD tabset 1"),
     bs4TabSetPanel(
       id = "tabset1", 
       side = "left",
       bs4TabPanel(
         tabName = "Tab 1",
         active = TRUE,
         p("Text 1"),
       ),
       bs4TabPanel(
         tabName = "Tab 2",
         active = FALSE,
         p("Text 2"),
       )
     ),
     actionButton("add2","ADD tabset 2"),
     bs4TabSetPanel(
       id = "tabset2", 
       side = "left",
       bs4TabPanel(
         tabName = "Tab 1",
         active = TRUE,
         p("Text 1"),
       ),
       bs4TabPanel(
         tabName = "Tab 2",
         active = FALSE,
         p("Text 2"),
       )
     )
   )
 )
 
 server <- function(input, output, session) {
   
   observeEvent(input$add1, {
     bs4InsertTab(
       inputId = "tabset1",
       bs4TabPanel(tabName = "Dynamic", "I am inserted"),
       target = "Tab 1",
       position = "after",
       select = FALSE
     )
   })
   
   observeEvent(input$add2, {
     bs4InsertTab(
       inputId = "tabset2",
       bs4TabPanel(tabName = "Dynamic", "I am inserted and active"),
       target = "Tab 1",
       position = "before",
       select = TRUE
     )
   })
   
 }
 shinyApp(ui, server)
 
 # with Datatable to test the Shiny.renderContent feature
 library(shiny)
 library(bs4Dash)
 library(DT)
 
 ui <-  bs4DashPage(
   sidebar_collapsed = T,
   sidebar = bs4DashSidebar(),
   bs4DashFooter(),
   body = bs4DashBody(
     actionButton("add", "Add 'Dynamic' tab"),
     bs4TabSetPanel(
       id = "tabset", 
       side = "left",
       bs4TabPanel(
         tabName = "default",
         "Tab 1"
       )
     )
   )
 )
 
 server <- function(input, output, session) {
   
   output$tbl = renderDT(
     iris, options = list(lengthChange = FALSE)
   )
   
   observeEvent(input$add, {
     bs4InsertTab(
       inputId = "tabset",
       bs4TabPanel(
         tabName = "DT", 
         dataTableOutput("tbl")
       ),
       target = "default",
       position = "after",
       select = TRUE
     )
   })
 }
 shinyApp(ui, server)
}

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