Create HTML tags — builder
R/tags.R
Description
Create an R object that represents an HTML tag. For convenience, common HTML
tags (e.g., <div>
) can be created by calling for their tag name directly
(e.g., div()
). To create less common HTML5 (or SVG) tags (e.g.,
<article>
), use the tags
list collection (e.g., tags$article()
). To
create other non HTML/SVG tags, use the lower-level tag()
constructor.
tags
p(..., .noWS = NULL, .renderHook = NULL)
h1(..., .noWS = NULL, .renderHook = NULL)
h2(..., .noWS = NULL, .renderHook = NULL)
h3(..., .noWS = NULL, .renderHook = NULL)
h4(..., .noWS = NULL, .renderHook = NULL)
h5(..., .noWS = NULL, .renderHook = NULL)
h6(..., .noWS = NULL, .renderHook = NULL)
a(..., .noWS = NULL, .renderHook = NULL)
br(..., .noWS = NULL, .renderHook = NULL)
div(..., .noWS = NULL, .renderHook = NULL)
span(..., .noWS = NULL, .renderHook = NULL)
pre(..., .noWS = NULL, .renderHook = NULL)
code(..., .noWS = NULL, .renderHook = NULL)
img(..., .noWS = NULL, .renderHook = NULL)
strong(..., .noWS = NULL, .renderHook = NULL)
em(..., .noWS = NULL, .renderHook = NULL)
hr(..., .noWS = NULL, .renderHook = NULL)
tag(`_tag_name`, varArgs, .noWS = NULL, .renderHook = NULL)
Arguments
- ...
Tag attributes (named arguments) and children (unnamed arguments). A named argument with an
NA
value is rendered as a boolean attributes (see example). Children may include any combination of:- .noWS
Character vector used to omit some of the whitespace that would normally be written around this tag. Valid options include
before
,after
,outside
,after-begin
, andbefore-end
. Any number of these options can be specified.- .renderHook
A function (or list of functions) to call when the
tag
is rendered. This function should have at least one argument (thetag
) and return anything that can be converted into tags viaas.tags()
. Additional hooks may also be added to a particulartag
viatagAddRenderHook()
.- _tag_name
A character string to use for the tag name.
- varArgs
List of tag attributes and children.
Value
A list()
with a shiny.tag
class that can be converted into an
HTML string via as.character()
and saved to a file with save_html()
.
See also
tagList()
, withTags()
, tagAppendAttributes()
, tagQuery()
Examples
tags$html(
tags$head(
tags$title('My first page')
),
tags$body(
h1('My first heading'),
p('My first paragraph, with some ', strong('bold'), ' text.'),
div(
id = 'myDiv', class = 'simpleDiv',
'Here is a div with some attributes.'
)
)
)
# html5 <audio> with boolean control attribute
# https://www.w3.org/TR/html5/infrastructure.html#sec-boolean-attributes
tags$audio(
controls = NA,
tags$source(
src = "myfile.wav",
type = "audio/wav"
)
)
# suppress the whitespace between tags
tags$span(
tags$strong("I'm strong", .noWS="outside")
)