insertUI {shiny} | R Documentation |
Insert a UI object into the app.
insertUI(selector, where = c("beforeBegin", "afterBegin", "beforeEnd", "afterEnd"), ui, multiple = FALSE, immediate = FALSE, session = getDefaultReactiveDomain())
selector |
A string that is accepted by jQuery's selector (i.e. the
string |
where |
Where your UI object should go relative to the selector:
Adapted from here. |
ui |
The UI object you want to insert. This can be anything that
you usually put inside your apps's |
multiple |
In case your selector matches more than one element,
|
immediate |
Whether the UI object should be immediately inserted into
the app when you call |
session |
The shiny session within which to call |
This function allows you to dynamically add an arbitrarily large UI
object into your app, whenever you want, as many times as you want.
Unlike renderUI
, the UI generated with insertUI
is not updatable as a whole: once it's created, it stays there. Each
new call to insertUI
creates more UI objects, in addition to
the ones already there (all independent from one another). To
update a part of the UI (ex: an input object), you must use the
appropriate render
function or a customized reactive
function. To remove any part of your UI, use removeUI
.
## Only run this example in interactive R sessions if (interactive()) { # Define UI ui <- fluidPage( actionButton("add", "Add UI") ) # Server logic server <- function(input, output, session) { observeEvent(input$add, { insertUI( selector = "#add", where = "afterEnd", ui = textInput(paste0("txt", input$add), "Insert some text") ) }) } # Complete app with UI and server components shinyApp(ui, server) }