Component Template
component-template.Rd
The template refers to the UI-generator of a given component. This is analagous to the UI function of a given shiny module.
Details
The component template function must be of the following structure (note the ns argument):
function(ns) {
# must either return an object that can
# be coerced to a `shiny::tags` object or a `shiny::tagList`
}
The following is an example of a valid template:
function(ns) {
shiny::div("Hello world!")
}
Namespacing
The template function requires one argument: ns
.
ns
is used identically to shiny modules, and
helps distinguish between component instances.
Slots
Component templates can be nested through the use of slots. Slots are placeholder elements that tell rsx where tags should be placed.
x <- component(
name = "slots",
template = function(ns) {
shiny::tagList(
shiny::tags$slot(),
shiny::p("bar")
)
}
)
print(x(shiny::p("foo")))
#> <rsx::instance> `slots`
#> <p>foo</p>
#> <p>bar</p>
You can also specify if you'd like content to be used in the case that a slot isn't filled -- this is typically called "fallback" content.
x <- component(
name = "fallback",
template = function(ns) {
shiny::tags$slot(
shiny::p("Hello!")
)
}
)
print(x())
#> <rsx::instance> `fallback`
#> <p>Hello!</p>
See also
Other components:
component-data
,
component-methods
,
component-styles
,
component()