ui_epoxy_html {epoxy} | R Documentation |
Epoxy HTML Output for Shiny
Description
A glue-like output for Shiny. ui_epoxy_html()
lets you use placeholders in
your HTML such as "{{first_name}}"
, that are provided values from the
server by giving render_epoxy()
a first_name
value. Unlike
ui_epoxy_mustache()
, updates are highly targeted: only the regions where
the server-side data have changed are updated in ui_epoxy_html()
.
Usage
ui_epoxy_html(
.id,
...,
.class = NULL,
.style = NULL,
.item_tag = "span",
.item_class = NULL,
.placeholder = "",
.sep = "",
.open = "{{",
.close = "}}",
.na = "",
.null = "",
.literal = FALSE,
.trim = FALSE,
.aria_live = c("polite", "off", "assertive"),
.aria_atomic = TRUE,
.class_item = deprecated(),
.container = deprecated(),
.container_item = deprecated()
)
epoxyHTML(.id, ...)
Arguments
.id |
The output id |
... |
UI elements or text (that will be treated as HTML), containing template variables. Use named values to provide initial placeholder values. |
.class , .style |
Classes and inline style directives added to the
|
.item_tag , .item_class |
The HTML element tag name and classes used to
wrap each template variable. By default, each template is wrapped in a
|
.placeholder |
Default placeholder if a template variable placeholder isn't provided. |
.sep |
[ |
.open |
[ |
.close |
[ |
.na |
[ |
.null |
[ |
.literal |
[ |
.trim |
[ |
.aria_live , .aria_atomic |
The
aria-live
and aria-atomic
attribute values for the entire template region. By default, with
If your template includes changes in lots of disparate areas, it would be
better to set |
.class_item |
|
.container |
Deprecated in
epoxy v1.0.0, where the container is now always |
.container_item |
Value
An HTML object.
Functions
HTML Markup
By default, placeholders are inserted into a <span>
element in your UI, with the classes specified in .class_item
.
ui_epoxy_html()
also supports an HTML markup syntax similar to
pug (an HTML preprocessor). As an
example, the markup syntax
"{{h3.example.basic#basic-three demo}}"
creates a demo
placeholder inside the following tag.
<h3 id="basic-three" class="example basic"></h3>
The placeholder template string follows the pattern {{<markup> <name>}}
.
The markup syntax comes first, separated from the placeholder name by a
space. The HTML element is first, followed by classes prefixed with .
or
and ID prefixed with #
. The template markup can contain only one element
and one ID, but many classes can be specified.
By default, the placeholder is assumed to be text content and any HTML
in the sent to the placeholder will be escaped — in other words if you sent
"<strong>word</strong>"
, you'd see that exact literal text in your app,
rather than an emboldened word. To mark a placeholder as safe to accept
HTML, use !!
before the placeholder, e.g. {{<markup> !!<name>}}
. So
{{h3 !!demo}}
will create an <h3>
tag that accepts HTML within it.
See Also
ui_epoxy_mustache()
, render_epoxy()
Examples
library(shiny)
ui <- fluidPage(
h2("ui_epoxy_html demo"),
ui_epoxy_html(
.id = "example",
.item_class = "inner",
fluidRow(
tags$div(
class = "col-xs-4",
selectInput(
inputId = "thing",
label = "What is this {{color}} thing?",
choices = c("apple", "banana", "coconut", "dolphin")
)
),
tags$div(
class = "col-xs-4",
selectInput(
inputId = "color",
label = "What color is the {{thing}}?",
c("red", "blue", "black", "green", "yellow")
)
),
tags$div(
class = "col-xs-4",
sliderInput(
inputId = "height",
label = "How tall is the {{color}} {{thing}}?",
value = 5,
min = 0,
max = 10,
step = 0.1,
post = "ft"
)
)
),
tags$p(class = "big", "The {{color}} {{thing}} is {{height}} feet tall."),
# Default values for placeholders above.
thing = "THING",
color = "COLOR",
height = "HEIGHT"
),
tags$style(HTML(
".big { font-size: 1.5em; }
.inner { background-color: rgba(254, 233, 105, 0.5);}
.epoxy-item__placeholder { color: #999999; background-color: unset; }"
))
)
server <- function(input, output, session) {
output$example <- render_epoxy(
thing = input$thing,
color = input$color,
height = input$height
)
}
if (interactive()) {
shinyApp(ui, server)
}
run_epoxy_example_app("ui_epoxy_html")