render: Render an HTML node tree to a character string

View source: R/tags.R

renderR Documentation

Render an HTML node tree to a character string

Description

Converts a hypertext.tag object (and all its descendants) into an HTML string. Text children are escaped; nested hypertext.tag children are rendered recursively.

Usage

render(x, ...)

## S3 method for class 'hypertext.tag'
render(x, file = "", write_mode = c("overwrite", "append"), ...)

## Default S3 method:
render(x, file = "", write_mode = c("overwrite", "append"), ...)

## S3 method for class 'hypertext.raw'
render(x, file = "", write_mode = c("overwrite", "append"), ...)

## S3 method for class 'list'
render(x, file = "", write_mode = c("overwrite", "append"), ...)

Arguments

x

hypertext.tag object, a string, or a list of these /// Required.

...

Further arguments passed from or to other methods.

file

String /// Optional. Path to file to print to.

write_mode

String /// Optional. Either "overwrite" (default) which overwrites the contents of file, or "append" which appends the HTML string to file.

Details

When file is provided, the rendered HTML is written to the specified file via cat() and the HTML string is returned invisibly.

Value

A single character string of HTML.

Examples

page <- tags$html(
  tags$head(
    tags$title("Home")
  ),
  tags$body(
    tags$h1("Welcome")
  )
)

# return HTML as a string:
render(page)

## Not run: 
  # write to a file:
  render(page, file = "index.html")

## End(Not run)


hypertext documentation built on April 18, 2026, 1:06 a.m.