Element's addable and editable tabs leave adding to the app: clicking "+"
reports input$<id>_tab_add, and the app decides what the new tab holds.
These are how, in the manner of shiny::insertTab() and
shiny::removeTab(). The content may hold any UI, this package's
components included.
Usage
insert_el_tab(
session = shiny::getDefaultReactiveDomain(),
id,
tab,
label = NULL,
content = NULL,
closable = NULL,
select = TRUE
)
remove_el_tab(session = shiny::getDefaultReactiveDomain(), id, name)Arguments
- session
Shiny session; the current one by default, as for
shiny::updateTextInput().- id
Tabs ID (un-namespaced).
- tab
The new tab: an
el_tab_pane(), asbslib::nav_insert()takes anav_panel()– or its name, withlabelandcontent.- label, content
The new tab's label and content, when
tabis a name.- closable
Whether it can be closed.
NULLfollows the tabs' own setting.- select
Whether to switch to it. Default
TRUE.- name
For
remove_el_tab(), the name of the tab to remove.
Examples
if (interactive()) {
library(shiny)
ui <- el_page(el_tabs(
"docs",
editable = TRUE,
tabs = list(
el_tab_pane("Tab 1", tags$p("First"), name = "t1")
)
))
server <- function(input, output, session) {
n <- 1
observeEvent(input$docs_tab_add, {
n <<- n + 1
insert_el_tab(
session,
"docs",
el_tab_pane(paste("Tab", n), tags$p("New"), name = paste0("t", n))
)
})
}
shinyApp(ui, server)
}