insertTab: Insert a tabPanel in a tabsetPanel

Description Usage Arguments Examples

View source: R/tabs.R

Description

Insert a tabPanel in a tabsetPanel

Usage

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

Arguments

inputId

tabsetPanel id.

tab

tabPanel to insert.

target

tabPanel 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
if (interactive()) {
 library(shiny)
 library(bs4Dash)
 
 shinyApp(
  ui = dashboardPage(
    header = dashboardHeader(),
    sidebar = dashboardSidebar(),
    controlbar = dashboardControlbar(),
    footer = dashboardFooter(),
    title = "Handle tabs",
    body = dashboardBody(
      actionButton("add", "Add 'Dynamic' tab"),
      actionButton("remove", "Remove 'Foo' tab"),
      actionButton("hideTab", "Hide 'Foo' tab"),
      actionButton("showTab", "Show 'Foo' tab"),
      br(), br(),
      tabBox(
        id = "tabs",
        title = "A card with tabs",
        selected = "Bar",
        status = "primary",
        solidHeader = FALSE, 
        type = "tabs",
        tabPanel("Hello", "This is the hello tab"),
        tabPanel("Foo", "This is the foo tab"),
        tabPanel("Bar", "This is the bar tab")
      )
    )
  ),
  server = function(input, output, session) {
    observeEvent(input$add, {
      insertTab(
        inputId = "tabs",
        tabPanel("Dynamic", "This a dynamically-added tab"),
        target = "Bar",
        select = TRUE
      )
    })
    
    observeEvent(input$remove, {
      removeTab(inputId = "tabs", target = "Foo")
    })
    
    observeEvent(input$hideTab, {
      hideTab(inputId = "tabs", target = "Foo")
    })
    
    observeEvent(input$showTab, {
      showTab(inputId = "tabs", target = "Foo")
    })
  }
 )
}

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