builder
HTML Builder Functions
Simple functions for constructing HTML documents.
Usage
tagsp(..., .noWS = NULL)
h1(..., .noWS = NULL)
h2(..., .noWS = NULL)
h3(..., .noWS = NULL)
h4(..., .noWS = NULL)
h5(..., .noWS = NULL)
h6(..., .noWS = NULL)
a(..., .noWS = NULL)
br(..., .noWS = NULL)
div(..., .noWS = NULL)
span(..., .noWS = NULL)
pre(..., .noWS = NULL)
code(..., .noWS = NULL)
img(..., .noWS = NULL)
strong(..., .noWS = NULL)
em(..., .noWS = NULL)
hr(..., .noWS = NULL)
Arguments
- ...
Attributes and children of the element. Named arguments become attributes, and positional arguments become children. Valid children are tags, single-character character vectors (which become text nodes), raw HTML (see
HTML
), andhtml_dependency
objects. You can also pass lists that contain tags, text nodes, or HTML. To use boolean attributes, use a named argument with aNA
value. (see example)- .noWS
A 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.
Details
The tags
environment contains convenience functions for all valid
HTML5 tags. To generate tags that are not part of the HTML5 specification,
you can use the tag()
function.
Dedicated functions are available for the most common HTML tags that do not conflict with common R functions.
The result from these functions is a tag object, which can be converted using
as.character()
.
References
W3C html specification about boolean attributes https://www.w3.org/TR/html5/infrastructure.html#sec-boolean-attributes
Examples
# NOT RUN {
doc <- 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.')
)
)
cat(as.character(doc))
# create an html5 audio tag with controls.
# controls is a boolean attributes
audio_tag <- tags$audio(
controls = NA,
tags$source(
src = "myfile.wav",
type = "audio/wav"
)
)
cat(as.character(audio_tag))
# suppress the whitespace between tags
oneline <- tags$span(
tags$strong("I'm strong", .noWS="outside")
)
cat(as.character(oneline))
# }