Debian Codegraph @

man/insertTab.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/insert-tab.R
3 \name{insertTab}
4 \alias{insertTab}
5 \alias{prependTab}
6 \alias{appendTab}
7 \alias{removeTab}
8 \title{Dynamically insert/remove a tabPanel}
9 \usage{
10 insertTab(
11 inputId,
12 tab,
13 target = NULL,
14 position = c("after", "before"),
15 select = FALSE,
16 session = getDefaultReactiveDomain()
17 )
18
19 prependTab(
20 inputId,
21 tab,
22 select = FALSE,
23 menuName = NULL,
24 session = getDefaultReactiveDomain()
25 )
26
27 appendTab(
28 inputId,
29 tab,
30 select = FALSE,
31 menuName = NULL,
32 session = getDefaultReactiveDomain()
33 )
34
35 removeTab(inputId, target, session = getDefaultReactiveDomain())
36 }
37 \arguments{
38 \item{inputId}{The \code{id} of the \code{tabsetPanel} (or
39 \code{navlistPanel} or \code{navbarPage}) into which \code{tab} will
40 be inserted/removed.}
41
42 \item{tab}{The item to be added (must be created with \code{tabPanel},
43 or with \code{navbarMenu}).}
44
45 \item{target}{If inserting: the \code{value} of an existing
46 \code{tabPanel}, next to which \code{tab} will be added.
47 If removing: the \code{value} of the \code{tabPanel} that
48 you want to remove. See Details if you want to insert next to/remove
49 an entire \code{navbarMenu} instead.}
50
51 \item{position}{Should \code{tab} be added before or after the
52 \code{target} tab?}
53
54 \item{select}{Should \code{tab} be selected upon being inserted?}
55
56 \item{session}{The shiny session within which to call this function.}
57
58 \item{menuName}{This argument should only be used when you want to
59 prepend (or append) \code{tab} to the beginning (or end) of an
60 existing \code{\link[=navbarMenu]{navbarMenu()}} (which must itself be part of
61 an existing \code{\link[=navbarPage]{navbarPage()}}). In this case, this argument
62 should be the \code{menuName} that you gave your \code{navbarMenu}
63 when you first created it (by default, this is equal to the value
64 of the \code{title} argument). Note that you still need to set the
65 \code{inputId} argument to whatever the \code{id} of the parent
66 \code{navbarPage} is. If \code{menuName} is left as \code{NULL},
67 \code{tab} will be prepended (or appended) to whatever
68 \code{inputId} is.}
69 }
70 \description{
71 Dynamically insert or remove a \code{\link[=tabPanel]{tabPanel()}} (or a
72 \code{\link[=navbarMenu]{navbarMenu()}}) from an existing \code{\link[=tabsetPanel]{tabsetPanel()}},
73 \code{\link[=navlistPanel]{navlistPanel()}} or \code{\link[=navbarPage]{navbarPage()}}.
74 }
75 \details{
76 When you want to insert a new tab before or after an existing tab, you
77 should use \code{insertTab}. When you want to prepend a tab (i.e. add a
78 tab to the beginning of the \code{tabsetPanel}), use \code{prependTab}.
79 When you want to append a tab (i.e. add a tab to the end of the
80 \code{tabsetPanel}), use \code{appendTab}.
81
82 For \code{navbarPage}, you can insert/remove conventional
83 \code{tabPanel}s (whether at the top level or nested inside a
84 \code{navbarMenu}), as well as an entire \code{\link[=navbarMenu]{navbarMenu()}}.
85 For the latter case, \code{target} should be the \code{menuName} that
86 you gave your \code{navbarMenu} when you first created it (by default,
87 this is equal to the value of the \code{title} argument).
88 }
89 \examples{
90 ## Only run this example in interactive R sessions
91 if (interactive()) {
92
93 # example app for inserting/removing a tab
94 ui <- fluidPage(
95 sidebarLayout(
96 sidebarPanel(
97 actionButton("add", "Add 'Dynamic' tab"),
98 actionButton("remove", "Remove 'Foo' tab")
99 ),
100 mainPanel(
101 tabsetPanel(id = "tabs",
102 tabPanel("Hello", "This is the hello tab"),
103 tabPanel("Foo", "This is the foo tab"),
104 tabPanel("Bar", "This is the bar tab")
105 )
106 )
107 )
108 )
109 server <- function(input, output, session) {
110 observeEvent(input$add, {
111 insertTab(inputId = "tabs",
112 tabPanel("Dynamic", "This a dynamically-added tab"),
113 target = "Bar"
114 )
115 })
116 observeEvent(input$remove, {
117 removeTab(inputId = "tabs", target = "Foo")
118 })
119 }
120
121 shinyApp(ui, server)
122
123
124 # example app for prepending/appending a navbarMenu
125 ui <- navbarPage("Navbar page", id = "tabs",
126 tabPanel("Home",
127 actionButton("prepend", "Prepend a navbarMenu"),
128 actionButton("append", "Append a navbarMenu")
129 )
130 )
131 server <- function(input, output, session) {
132 observeEvent(input$prepend, {
133 id <- paste0("Dropdown", input$prepend, "p")
134 prependTab(inputId = "tabs",
135 navbarMenu(id,
136 tabPanel("Drop1", paste("Drop1 page from", id)),
137 tabPanel("Drop2", paste("Drop2 page from", id)),
138 "------",
139 "Header",
140 tabPanel("Drop3", paste("Drop3 page from", id))
141 )
142 )
143 })
144 observeEvent(input$append, {
145 id <- paste0("Dropdown", input$append, "a")
146 appendTab(inputId = "tabs",
147 navbarMenu(id,
148 tabPanel("Drop1", paste("Drop1 page from", id)),
149 tabPanel("Drop2", paste("Drop2 page from", id)),
150 "------",
151 "Header",
152 tabPanel("Drop3", paste("Drop3 page from", id))
153 )
154 )
155 })
156 }
157
158 shinyApp(ui, server)
159
160 }
161 }
162 \seealso{
163 \code{\link[=showTab]{showTab()}}
164 }