ui_epoxy_markdown {epoxy} | R Documentation |
Epoxy Markdown Template for Shiny
Description
Create reactive HTML from a Markdown template. ui_epoxy_markdown()
uses the
same template syntax as ui_epoxy_html()
, but rather than requiring HTML
inputs, you can write in markdown. The template is first rendered from
markdown to HTML using pandoc::pandoc_convert()
(if pandoc is
available) or commonmark::markdown_html()
otherwise.
Usage
ui_epoxy_markdown(
.id,
...,
.markdown_fn = NULL,
.markdown_args = list(),
.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()
)
Arguments
.id |
The output id |
... |
Unnamed arguments are treated as lines of markdown text, and named arguments are treated as initial values for templated variables. |
.markdown_fn |
The function used to convert the markdown to HTML. This
function is passed the markdown text as a character vector for the first
argument and any additional arguments from the list |
.markdown_args |
A list of arguments to pass to
|
.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.
See Also
ui_epoxy_html()
, ui_epoxy_mustache()
, render_epoxy()
Examples
library(shiny)
# Shiny epoxy template functions don't support inline transformations,
# so we still have to do some prep work ourselves.
bechdel <- epoxy::bechdel
as_dollars <- scales::label_dollar(
scale_cut = scales::cut_short_scale()
)
bechdel$budget <- as_dollars(bechdel$budget)
bechdel$domgross <- as_dollars(bechdel$domgross)
vowels <- c("a", "e", "i", "o", "u")
bechdel$genre <- paste(
ifelse(substr(tolower(bechdel$genre), 1, 1) %in% vowels, "an", "a"),
tolower(bechdel$genre)
)
movie_ids <- rlang::set_names(
bechdel$imdb_id,
bechdel$title
)
ui <- fixedPage(
fluidRow(
column(
width = 3,
selectInput("movie", "Movie", movie_ids),
uiOutput("poster")
),
column(
width = 9,
ui_epoxy_markdown(
.id = "about_movie",
"
## {{title}}
**Released:** {{ year }} \\
**Rated:** {{ rated }} \\
**IMDB Rating:** {{ imdb_rating }}
_{{ title }}_ is {{ genre }} film released in {{ year }}.
It was filmed in {{ country }} with a budget of {{ budget }}
and made {{ domgross }} at the box office.
_{{ title }}_ recieved a Bechdel rating of **{{ bechdel_rating }}**
for the following plot:
> {{ plot }}
"
)
)
)
)
server <- function(input, output, session) {
movie <- reactive({
bechdel[bechdel$imdb_id == input$movie, ]
})
output$about_movie <- render_epoxy(.list = movie())
output$poster <- renderUI(
img(
src = movie()$poster,
alt = paste0("Poster for ", movie()$title),
style = "max-height: 400px; max-width: 100%; margin: 0 auto; display: block;"
)
)
}
if (interactive()) {
shinyApp(ui, server)
}
run_epoxy_example_app("ui_epoxy_markdown")