| lt_export | R Documentation |
Save a table to disk. The output format is chosen from the file extension
of output: .html writes an HTML table, .pdf writes a vector PDF, and
any other extension writes a PNG. PDF and PNG are produced by rendering the
table in a headless Chromium browser (via xfun::browser_print()).
lt_export(
x,
output = "lt.html",
method = c("auto", "node", "browser", "raw"),
css = TRUE,
fragment = FALSE,
tidy = FALSE,
crop = TRUE,
width = NULL,
padding = 8,
browser = NULL,
...
)
x |
An |
output |
Output file path. Its extension selects the format: |
method |
How to produce the HTML |
css |
Whether to include the lt.css runtime stylesheet in the HTML
output. User CSS from |
fragment |
If |
tidy |
Whether to pretty-print the baked |
crop |
Whether to crop the PDF/PNG tightly to the table, removing the
surrounding page whitespace. This adds a preliminary browser pass to
measure the rendered table. Set to |
width |
The width of the table in CSS pixels. By default ( |
padding |
Padding in CSS pixels to keep around the table when
cropping. A single value (all sides) or a length-two vector
|
browser |
Path to the Chromium-based browser; passed to
|
... |
Passed to |
For .html output, method controls how the <table> is produced:
"raw" writes the JavaScript-spec HTML, so the table is built in the
browser by the lt.js runtime when the file is viewed; the other methods
bake a static <table> up front by running lt.js once (via "node" in
Node.js or "browser" in a headless Chromium browser; "auto" picks Node
if available, else the browser), so the saved file needs no JavaScript to
view. method, css, fragment, and tidy apply only to .html output.
The output path, or (when output is NA) the HTML as a string.
When the option lt.lt_static is set to a list of arguments (e.g.,
options(lt.lt_static = list(css = FALSE))), the
knit_print and record_print
methods emit the same static HTML table as lt_export(x, "*.html") (using
those arguments as method/css/fragment) instead of the default
JavaScript-based spec. This is useful for output formats that support raw
HTML but cannot run JavaScript (e.g., GitHub Flavored Markdown).
tbl = lt(head(mtcars))
# HTML with the JavaScript spec (table built by lt.js when viewed)
lt_export(tbl, NA, method = 'raw') # character output
f1 = tempfile(fileext = '.html')
lt_export(tbl, f1, method = 'raw') # file output
# Bake a static <table> (needs Node.js or a headless browser).
if (lt:::can_bake())
lt_export(tbl, NA, method = 'auto', fragment = TRUE, css = FALSE)
# PDF / PNG are rendered in a headless browser and cropped to the table.
f2 = tempfile(fileext = '.pdf')
f3 = tempfile(fileext = '.png')
if (lt:::has_browser()) {
lt_export(tbl, f2)
lt_export(tbl, f3, width = 400)
}
unlink(c(f1, f2, f3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.