Learn R Programming

bs4Dash (version 0.5.0)

bs4InsertTab: Insert a bs4TabPanel in a bs4TabSetPanel

Description

Insert a bs4TabPanel in a bs4TabSetPanel

Usage

bs4InsertTab(
  inputId,
  tab,
  target,
  position = c("before", "after"),
  select = FALSE,
  session = shiny::getDefaultReactiveDomain()
)

Arguments

inputId
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

Run this code
# NOT RUN {
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)
}
# }

Run the code above in your browser using DataLab