as_raw_html: Get the HTML content of a *gt* table

View source: R/export.R

as_raw_htmlR Documentation

Get the HTML content of a gt table

Description

Get the HTML content from a gt_tbl object as a single-element character vector. By default, the generated HTML will have inlined styles, where CSS styles (that were previously contained in CSS rule sets external to the ⁠<table> element⁠) are included as style attributes in the HTML table's tags. This option is preferable when using the output HTML table in an emailing context.

Usage

as_raw_html(data, inline_css = TRUE)

Arguments

data

The gt table data object

⁠obj:<gt_tbl>⁠ // required

This is the gt table object that is commonly created through use of the gt() function.

inline_css

Use inline CSS

⁠scalar<logical>⁠ // default: TRUE

An option to supply styles to table elements as inlined CSS styles. This is useful when including the table HTML as part of an HTML email message body, since inlined styles are largely supported in email clients over using CSS in a ⁠<style>⁠ block.

Examples

Use a subset of the gtcars dataset to create a gt table. Add a header with tab_header() and then export the table as HTML code with inlined CSS styles using as_raw_html().

tab_html <-
  gtcars |>
  dplyr::select(mfr, model, msrp) |>
  dplyr::slice_head(n = 5) |>
  gt() |>
  tab_header(
    title = md("Data listing from **gtcars**"),
    subtitle = md("`gtcars` is an R dataset")
  ) |>
  as_raw_html()

What's returned is a single-element vector containing the HTML for the table. It has only the ⁠<table>...</table>⁠ part so it's not a complete HTML document but rather an HTML fragment.

Function ID

13-2

Function Introduced

v0.2.0.5 (March 31, 2020)

See Also

Other table export functions: as_gtable(), as_latex(), as_rtf(), as_word(), extract_body(), extract_cells(), extract_summary(), gtsave()


rstudio/gt documentation built on Nov. 2, 2024, 5:53 p.m.