Insert a tabPanel in a tabsetPanel
Usage
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
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")
})
}
)
}