The official tutorial by RStudio is a little unclear on how to actually use the tagList() function for creating a namespaced ID in Shiny modules. The Shiny documentation does not help much either. What exactly am I supposed to put inside the tagList() function? Should I only wrap input arguments in a tagList(), like shown in all examples and video tutorials, or can I put other elements in there, such as a sidebarPanel()?
tagList()
creates nothing but a simple list of tags. The definition is
> tagList
function (...)
{
lst <- list(...)
class(lst) <- c("shiny.tag.list", "list")
return(lst)
}
It's a simple list having a special class shiny.tag.list
. You use it when you create a module, where the UI of the module needs to return a simple page, like a fluidPage
etc. If you don't want to create an extra UI for the module, you just return a few UI elements wrapped inside tagList
and take care of the UI outside of the module. For example:
library(shiny)
moduleUI <- function(id){
ns <- NS(id)
# return a list of tags
tagList(h4("Select something"),
selectInput(ns("select"), "Select here", choices=1:10))
}
module <- function(input, output, session){}
ui <- shinyUI(
fluidPage(wellPanel(moduleUI("module"))) # wrap everything that comes from the moduleUI in a wellPanel
)
server <- shinyServer(function(input, output, session){
callModule(module, "module")
})
shinyApp(ui = ui, server = server)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With