save_dtsmartr: Save a dtsmartr widget to an HTML file

View source: R/save_dtsmartr.R

save_dtsmartrR Documentation

Save a dtsmartr widget to an HTML file

Description

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 .html extension 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. When FALSE, a companion ⁠<file>_files/⁠ directory is created next to the HTML file containing the JS/CSS assets - both must be kept together when sharing. Use FALSE for 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 TRUE and the session is interactive, the saved HTML file is opened automatically in the default web browser immediately after saving. Defaults to FALSE.

background

Character string. CSS colour for the page background. Defaults to "white".

libdir

Character string or NULL. When selfcontained = FALSE, the path to write the dependency libraries. Passed directly to htmlwidgets::saveWidget(). Defaults to NULL (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 to NULL (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 to TRUE.

Details

Selfcontained vs. non-selfcontained

selfcontained Output Best for
TRUE (default) Single .html file Email / sharing
FALSE .html + ⁠_files/⁠ folder Local use / large datasets

File size

Self-contained files embed the React runtime and widget code (~120 KB gzipped) along with the data. For very large datasets (> 100 k rows) or when generating many files, prefer selfcontained = FALSE.

Browser compatibility

The generated HTML works in all modern browsers (Chrome, Firefox, Edge, Safari 14+). No internet connection is required.

Value

The absolute path to the saved HTML file, invisibly.

See Also

dtsmartr() for creating the widget object interactively, htmlwidgets::saveWidget() for the underlying save mechanism.

Examples


# == Basic usage =============================================================

# Save mtcars as a self-contained HTML (single portable file)
tmp_file <- tempfile(fileext = ".html")
save_dtsmartr(mtcars, tmp_file)

# Open in the browser right after saving
tmp_file_open <- tempfile(fileext = ".html")
save_dtsmartr(mtcars, tmp_file_open, open = TRUE)

# == Custom options ==========================================================

tmp_file_opts <- tempfile(fileext = ".html")
save_dtsmartr(
  mtcars, 
  tmp_file_opts, 
  options = dtsmartr_options(hidden_columns = "cyl", advanced_filter = FALSE)
)



dtsmartr documentation built on June 17, 2026, 1:08 a.m.