Skip to contents

insertF7Tab inserts an f7Tab in an f7Tabs.

Usage

insertF7Tab(
  id,
  tab,
  target = NULL,
  position = c("before", "after"),
  select = FALSE,
  session = shiny::getDefaultReactiveDomain()
)

Arguments

id

f7Tabs id.

tab

f7Tab to insert.

target

f7Tab 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()) {
 # Insert after
 library(shiny)
 library(shinyMobile)
 shinyApp(
   ui = f7Page(
     title = "Insert a tab Before the target",
     f7TabLayout(
       navbar = f7Navbar(
         title = "insertF7Tab",
         hairline = FALSE,
         shadow = TRUE,
         leftPanel = TRUE,
         rightPanel = TRUE
       ),
       f7Tabs(
         animated = TRUE,
         id = "tabs",
         f7Tab(
           tabName = "Tab1",
           icon = f7Icon("airplane"),
           active = TRUE,
           "Tab 1",
           f7Button(inputId = "add", label = "Add tabs")
         ),
         f7Tab(
           tabName = "Tab2",
           icon = f7Icon("today"),
           active = FALSE,
           f7Button(inputId="stay", label = "Stay"),
           "Tab 2"
         )
       )
     )
   ),
   server = function(input, output, session) {
     observeEvent(input$stay, {
       f7Toast("Please stay")
     })
     observeEvent(input$add, {
       insertF7Tab(
         id = "tabs",
         position = "after",
         target = "Tab1",
         tab = f7Tab (
           # Use multiple elements to test for accessor function
           f7Text(inputId = "my_text", label ="Enter something", placeholder = "What?"),
           f7Text(inputId = "my_other", label ="Else:", placeholder = "Else ?"),
           tabName = paste0("tabx_", input$go),
           "Test2",
           icon = f7Icon("app_badge")
         ),
         select = TRUE
       )
     })
   }
 )
 # Insert in an empty tabsetpanel
 library(shiny)
 ui <- f7Page(
   f7SingleLayout(
     navbar = f7Navbar(),
     f7Button("add", "Add 'Dynamic' tab"),
     br(),
     f7Tabs(id = "tabs"),
   )
 )
 server <- function(input, output, session) {
   observeEvent(input$add, {
     insertF7Tab(
       id = "tabs",
       f7Tab(title = "Dynamic", tabName = "Dynamic", "This a dynamically-added tab"),
       target = NULL
     )
   })
 }
 shinyApp(ui, server)
}