gt (version 0.2.2)

as_raw_html: 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

A table object that is created using the gt() function.

inline_css

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.

Function ID

13-2

See Also

Other Export Functions: as_latex(), as_rtf(), extract_summary(), gtsave()

Examples

Run this code
# NOT RUN {
# Use `gtcars` to create a gt table;
# add a header and then export as
# HTML code with CSS inlined
tab_html <-
  gtcars %>%
  dplyr::select(mfr, model, msrp) %>%
  dplyr::slice(1:5) %>%
  gt() %>%
  tab_header(
    title = md("Data listing from **gtcars**"),
    subtitle = md("`gtcars` is an R dataset")
  ) %>%
  as_raw_html()

# `tab_html` is a single-element vector
# containing inlined HTML for the table;
# it has only the `<table>...</table>` part
# so it's not a complete HTML document but
# rather an HTML fragment
tab_html %>%
  substr(1, 700) %>%
  cat()

# }

Run the code above in your browser using DataCamp Workspace