Exports any data.frame as a fully interactive, standalone HTML file powered
by the dtsmartr widget. The resulting file can be opened in any modern web
browser without an active R session or internet connection, making it ideal
for offline use and sharing with collaborators.
Usage
save_dtsmartr(
data,
file,
selfcontained = TRUE,
title = "dtsmartr",
open = FALSE,
background = "white",
libdir = NULL,
width = NULL,
height = NULL,
elementId = NULL,
options = dtsmartr_options(),
verbose = TRUE
)Arguments
- data
A
data.frame(or object coercible to one) to explore.- file
Character string. Path to the output HTML file. The
.htmlextension is appended automatically if omitted.- selfcontained
Logical. When
TRUE(default), all JavaScript, CSS, and data are embedded directly inside the HTML file, producing a single portable file. WhenFALSE, a companion<file>_files/directory is created next to the HTML file containing the JS/CSS assets - both must be kept together when sharing. UseFALSEfor large datasets where a single file would be impractically large.- title
Character string. Browser tab / window title for the saved HTML page. Defaults to
"dtsmartr".- open
Logical. When
TRUEand the session is interactive, the saved HTML file is opened automatically in the default web browser immediately after saving. Defaults toFALSE.- background
Character string. CSS colour for the page background. Defaults to
"white".- libdir
Character string or
NULL. Whenselfcontained = FALSE, the path to write the dependency libraries. Passed directly tohtmlwidgets::saveWidget(). Defaults toNULL(creates<file>_files/next to the output file).- width
Numeric or
NULL. Widget width in pixels.NULL(default) uses the full page width.- height
Numeric or
NULL. Widget height in pixels.NULL(default) fills the viewport (maximised mode).- elementId
Character string or
NULL. CSS id for the widget's root<div>. Defaults toNULL(auto-generated).- options
Named list of UI options generated by
dtsmartr_options().- verbose
Logical. When
TRUE, prints a confirmation message with the resolved absolute path of the saved file. Defaults toTRUE.
Details
Selfcontained vs. non-selfcontained
selfcontained | Output | Best for |
TRUE (default) | Single .html file | Email / sharing |
FALSE | .html + _files/ folder | Local use / large datasets |
See also
dtsmartr() for creating the widget object interactively,
htmlwidgets::saveWidget() for the underlying save mechanism.
Examples
# \donttest{
# == Basic usage =============================================================
# Save mtcars as a self-contained HTML (single portable file)
tmp_file <- tempfile(fileext = ".html")
save_dtsmartr(mtcars, tmp_file)
#> dtsmartr saved (self-contained): C:\Users\hp\AppData\Local\Temp\Rtmp2nAjnX\file50ac4d6e7892.html
# Open in the browser right after saving
tmp_file_open <- tempfile(fileext = ".html")
save_dtsmartr(mtcars, tmp_file_open, open = TRUE)
#> dtsmartr saved (self-contained): C:\Users\hp\AppData\Local\Temp\Rtmp2nAjnX\file50ac532b3130.html
# == Custom options ==========================================================
tmp_file_opts <- tempfile(fileext = ".html")
save_dtsmartr(
mtcars,
tmp_file_opts,
options = dtsmartr_options(hidden_columns = "cyl", advanced_filter = FALSE)
)
#> dtsmartr saved (self-contained): C:\Users\hp\AppData\Local\Temp\Rtmp2nAjnX\file50ac51966b70.html
# }
