Description Usage Arguments Details See Also Examples
Dynamically insert or remove a tabPanel
(or a
navbarMenu
) from an existing tabsetPanel
,
navlistPanel
or navbarPage
.
1 2 3 4 5 6 7 8 9 10 | insertTab(inputId, tab, target, position = c("before", "after"),
select = FALSE, session = getDefaultReactiveDomain())
prependTab(inputId, tab, select = FALSE, menuName = NULL,
session = getDefaultReactiveDomain())
appendTab(inputId, tab, select = FALSE, menuName = NULL,
session = getDefaultReactiveDomain())
removeTab(inputId, target, session = getDefaultReactiveDomain())
|
inputId |
The |
tab |
The item to be added (must be created with |
target |
If inserting: the |
position |
Should |
select |
Should |
session |
The shiny session within which to call this function. |
menuName |
This argument should only be used when you want to
prepend (or append) |
When you want to insert a new tab before or after an existing tab, you
should use insertTab
. When you want to prepend a tab (i.e. add a
tab to the beginning of the tabsetPanel
), use prependTab
.
When you want to append a tab (i.e. add a tab to the end of the
tabsetPanel
), use appendTab
.
For navbarPage
, you can insert/remove conventional
tabPanel
s (whether at the top level or nested inside a
navbarMenu
), as well as an entire navbarMenu
.
For the latter case, target
should be the menuName
that
you gave your navbarMenu
when you first created it (by default,
this is equal to the value of the title
argument).
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | ## Only run this example in interactive R sessions
if (interactive()) {
# example app for inserting/removing a tab
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("add", "Add 'Dynamic' tab"),
actionButton("remove", "Remove 'Foo' tab")
),
mainPanel(
tabsetPanel(id = "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"
)
})
observeEvent(input$remove, {
removeTab(inputId = "tabs", target = "Foo")
})
}
shinyApp(ui, server)
# example app for prepending/appending a navbarMenu
ui <- navbarPage("Navbar page", id = "tabs",
tabPanel("Home",
actionButton("prepend", "Prepend a navbarMenu"),
actionButton("append", "Append a navbarMenu")
)
)
server <- function(input, output, session) {
observeEvent(input$prepend, {
id <- paste0("Dropdown", input$prepend, "p")
prependTab(inputId = "tabs",
navbarMenu(id,
tabPanel("Drop1", paste("Drop1 page from", id)),
tabPanel("Drop2", paste("Drop2 page from", id)),
"------",
"Header",
tabPanel("Drop3", paste("Drop3 page from", id))
)
)
})
observeEvent(input$append, {
id <- paste0("Dropdown", input$append, "a")
appendTab(inputId = "tabs",
navbarMenu(id,
tabPanel("Drop1", paste("Drop1 page from", id)),
tabPanel("Drop2", paste("Drop2 page from", id)),
"------",
"Header",
tabPanel("Drop3", paste("Drop3 page from", id))
)
)
})
}
shinyApp(ui, server)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.