mirror of
https://github.com/rstudio/shiny.git
synced 2026-02-07 21:26:08 -05:00
104 lines
3.4 KiB
R
104 lines
3.4 KiB
R
% Generated by roxygen2: do not edit by hand
|
|
% Please edit documentation in R/insert-tab.R
|
|
\name{insertTab}
|
|
\alias{insertTab}
|
|
\alias{prependTab}
|
|
\alias{appendTab}
|
|
\alias{removeTab}
|
|
\title{Dynamically insert/remove a tabPanel}
|
|
\usage{
|
|
insertTab(inputId, tab, target, position = c("before", "after"),
|
|
session = getDefaultReactiveDomain())
|
|
|
|
prependTab(inputId, tab, menuName = NULL,
|
|
session = getDefaultReactiveDomain())
|
|
|
|
appendTab(inputId, tab, menuName = NULL,
|
|
session = getDefaultReactiveDomain())
|
|
|
|
removeTab(inputId, target, session = getDefaultReactiveDomain())
|
|
}
|
|
\arguments{
|
|
\item{inputId}{The \code{id} of the \code{tabsetPanel} (or
|
|
\code{navlistPanel} or \code{navbarPage})into which \code{tab} will
|
|
be inserted/removed.}
|
|
|
|
\item{tab}{The tab element to be added (must be created with
|
|
\code{tabPanel}).}
|
|
|
|
\item{target}{The \code{value} of an existing \code{tabPanel}, next to
|
|
which \code{tab} will be added.}
|
|
|
|
\item{position}{Should \code{tab} be added before or after the
|
|
\code{target} tab?}
|
|
|
|
\item{session}{The shiny session within which to call \code{insertTab}.}
|
|
|
|
\item{menuName}{This argument should only be used when you want to
|
|
prepend (or append) \code{tab} to the beginning (or end) of an
|
|
existing \code{\link{navbarMenu}} (which must itself be part of
|
|
an existing \code{\link{navbarPage}}). In this case, this argument
|
|
should be the \code{menuName} that you gave your \code{navbarMenu}
|
|
when you first created it (by default, this is equal to the value
|
|
of the \code{title} argument). Note that you still need to set the
|
|
\code{inputId} argument to whatever the \code{id} of the parent
|
|
\code{navbarPage} is. If \code{menuName} is left as \code{NULL},
|
|
\code{tab} will be prepended (or appended) to whatever
|
|
\code{inputId} is.}
|
|
}
|
|
\description{
|
|
Dynamically insert or remove a \code{\link{tabPanel}} from an existing
|
|
\code{\link{tabsetPanel}}, \code{\link{navlistPanel}} or
|
|
\code{\link{navbarPage}}.
|
|
}
|
|
\details{
|
|
When you want to insert a new tab before of after an existing tab, you
|
|
should use \code{insertTab}. When you want to prepend a tab (i.e. add a
|
|
tab to the beginning of the \code{tabsetPanel}), use \code{prependTab}.
|
|
When you want to append a tab (i.e. add a tab to the end of the
|
|
\code{tabsetPanel}), use \code{appendTab}.
|
|
|
|
For \code{navbarPage}, you can insert/remove conventional
|
|
\code{tabPanel}s (whether at the top level or nested inside a
|
|
\code{navbarMenu}), as well as an entire \code{\link{navbarMenu}}.
|
|
For the latter case, \code{target} should be the \code{menuName} that
|
|
you gave your \code{navbarMenu} when you first created it (by default,
|
|
this is equal to the value of the \code{title} argument).
|
|
}
|
|
\examples{
|
|
## Only run this example in interactive R sessions
|
|
if (interactive()) {
|
|
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)
|
|
}
|
|
}
|
|
\seealso{
|
|
\code{\link{showTab}}
|
|
}
|