builder: HTML Builder Functions

Description Usage Arguments Details References Examples

Description

Simple functions for constructing HTML documents.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
tags

p(..., .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), and html_dependency objects. You can also pass lists that contain tags, text nodes, or HTML. To use boolean attributes, use a named argument with a NA 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, before-end, and inside. 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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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))

Example output

<html>
  <body>
    <h1>My first heading</h1>
    <p>
      My first paragraph, with some 
      <strong>bold</strong>
       text.
    </p>
    <div id="myDiv" class="simpleDiv">Here is a div with some attributes.</div>
  </body>
</html><audio controls>
  <source src="myfile.wav" type="audio/wav"/>
</audio><span>
  <strong .noWS="outside">I'm strong</strong>
</span>

htmltools documentation built on July 8, 2020, 6:19 p.m.

Related to builder in htmltools...