2.4 Alternative way to write tags

  • Raw HTML can be included via the htmltools::HTML() function. It prevents HTML content not being properly recognized:

    div("Hello <i>world</i>")
    <div>Hello &lt;i&gt;world&lt;/i&gt;</div>
    div(HTML("Hello <i>world</i>"))
    <div>Hello <i>world</i></div>
  • When creating HTML elements for a Shiny app, it’s recommended to do so via R, instead of mixing it with raw HTML:

    # Same output
    HTML("<div>lorem</div>")
    <div>lorem</div>
    div("lorem")
    <div>lorem</div>
    # Differen class
    class(HTML("<div>lorem</div>"))
    [1] "html"      "character"
    class(div("lorem"))
    [1] "shiny.tag"
  • The shiny.tag class is required for some tag-related functions which we’ll cover in the next sections.