- Build
- Frontend
- User interface
- Shiny HTML Tags Glossary
Shiny HTML Tags Glossary
Garrett Grolemund
August 8, 2017
In Customize your Shiny UI with HTML you saw that Shiny provides a list of functions named tags
. Each function in the list creates an HTML tag that you can use to layout your Shiny App. But what if you are unfamiliar with HTML tags? The glossary below explains what the most popular tags in tags
do.
tags
The shiny::tags
object contains R functions that recreate 110 HTML tags.
names(tags)
## [1] "a" "abbr" "address" "area" "article"
## [6] "aside" "audio" "b" "base" "bdi"
## [11] "bdo" "blockquote" "body" "br" "button"
## [16] "canvas" "caption" "cite" "code" "col"
## [21] "colgroup" "command" "data" "datalist" "dd"
## [26] "del" "details" "dfn" "div" "dl"
## [31] "dt" "em" "embed" "eventsource" "fieldset"
## [36] "figcaption" "figure" "footer" "form" "h1"
## [41] "h2" "h3" "h4" "h5" "h6"
## [46] "head" "header" "hgroup" "hr" "html"
## [51] "i" "iframe" "img" "input" "ins"
## [56] "kbd" "keygen" "label" "legend" "li"
## [61] "link" "mark" "map" "menu" "meta"
## [66] "meter" "nav" "noscript" "object" "ol"
## [71] "optgroup" "option" "output" "p" "param"
## [76] "pre" "progress" "q" "ruby" "rp"
## [81] "rt" "s" "samp" "script" "section"
## [86] "select" "small" "source" "span" "strong"
## [91] "style" "sub" "summary" "sup" "table"
## [96] "tbody" "td" "textarea" "tfoot" "th"
## [101] "thead" "time" "title" "tr" "track"
## [106] "u" "ul" "var" "video" "wbr"
You can use any of these functions by subsetting the tags
list. For example to create an h1
header in HTML, run:
Some tags functions come with a helper function that makes accessing them easier. For example, the shiny::h1
function is a wrapper for tags$h1
.
However, you can access many of the functions in tags only through tags
because they share a name with a common R function.
The glossary below explains what the most popular tag functions do. The tag functions that do not appear here are less popular, but still useful. You can look them up at an HTML documentation site such as w3schools.
Note about non-standard attribute names
Like in all R code, if you need to use a non-standard argument or variable name, you will also need to use backticks around it. This can come up for attribute names, since a few of these will include dashes. For example, the following code will not work:
Here’s the correct version:
a
Creates a link to a web page. You can access the “a” tag with the helper function a
.
Common Attributes | Description |
---|---|
href | the address of the web page to link to |
audio
Adds an audio element (e.g., a sound to your app).
Common Attributes | Description |
---|---|
autoplay | A valueless attribute. If present, audio starts playing automatically when loaded |
controls | A valueless attribute. If present, play controls are displayed |
src | The location of the audio file to play |
type | The type of file to play |
b
Creates bold text.
blockquote
Creates a block of quoted text. Usually it is displayed in a special way.
Common Attributes | Description |
---|---|
cite | the source of the quote |
br
Creates a line break. You can use the helper function br
.
code
Creates text formatted as computer code. You can use the helper function code
.
div
Creates a section (e.g., “division”) of an HTML document. divs provide a useful hook for CSS styling. You can use the helper function div
.
Common Attributes | Description |
---|---|
class | The class of the div, a useful way to style the div with CSS |
id | The ID of the div, a useful way to style the div with CSS |
style | CSS styling to apply to the div |
em
Creates emphasized (e.g., italicized) text. You can use the helper function em
.
embed
Embed a plug-in or third party application.
Common Attributes | Description |
---|---|
src | The source of the file to embed |
type | The MIME type of the embedded content |
height | The height of the embedded content |
width | The width of the embedded content |
h1, h2, h3, h4, h5, h6
Adds hierarchical headings. h1
creates a first level heading and h2
through h6
create a hierarchy of decreasing subheadings. You can use the helper functions h1
, h2
, h3
, h4
, h5
, h6
.
tags$div(
tags$h1("Heading"),
tags$h2("Subheading"),
tags$h3("Subsubheading"),
tags$h4("Subsubsubheading"),
tags$h5("Subsubsubsubheading"),
tags$h6("Subsubsubsubsubheading")
)
## <div>
## <h1>Heading</h1>
## <h2>Subheading</h2>
## <h3>Subsubheading</h3>
## <h4>Subsubsubheading</h4>
## <h5>Subsubsubsubheading</h5>
## <h6>Subsubsubsubsubheading</h6>
## </div>
hr
Adds a horizontal line (e.g., horizontal rule). You can use the helper function hr
.
i
Creates italicized text.
iframe
Creates an inline frame to embed an HTML document in.
Common Attributes | Description |
---|---|
src | The URL of the HTML document to embed |
srcdoc | A raw HTML document to embed |
scrolling | Should iframe display scrollbars (yes , no , auto ) |
seamless | A valueless attribute. Should the iframe seem like part of the web page? |
height | The height of the iframe |
width | The width of the iframe |
name | The name of the iframe |
img
Creates an image. You can use the helper function img
.
Common Attributes | Description |
---|---|
src | The source of the image to embed |
height | The height of the image |
width | The width of the image |
link
Creates a link to a separate document. Normally used with CSS style sheets.
ol and li
Create an ordered list (i.e., a numbered list).
p
Create a paragraph (a block of text that begins on its own line). You can access the p tag with the helper function p
too.
pre
Create pre-formatted text, text that looks like computer code. You can use the helper function pre
.
script
Add a client-side script such as javascript. You must wrap the actual script in HTML
to prevent it from being passed as text.
span
Create a group of inline elements. Normally used to style a string of text. You can use the helper function span
.
strong
Create bold text. You can use the helper function strong
.
style
Create style specifications. A way to add CSS styles directly to your Shiny App.
sub, sup
Create subscript or super script.
ul and li
Create an unordered list (i.e., a list of bullet points).
video
Add a video.
Common Attributes | Description |
---|---|
autoplay | A valueless attribute. If present, video starts playing automatically when loaded |
controls | A valueless attribute. If present, Shiny will display play controls. |
src | The location of the video file to play |
height | The height of the video |
width | The width of the video |