---
title: "Saving HTML Reports & Documents"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Saving HTML Reports & Documents}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
`dtsmartr` supports exporting your interactive grid sessions as offline-capable standalone HTML files, as well as embedding them seamlessly inside **R Markdown (.Rmd)** and **Quarto (.qmd)** dynamic reports.
---
## 1. Standalone HTML Reports (`save_dtsmartr`)
Export any data frame as a standalone web app using the `save_dtsmartr()` function:
```r
library(dtsmartr)
# Export as a self-contained portable HTML file
save_dtsmartr(
data = mtcars,
file = "reports/mtcars_dashboard.html"
)
```
The resulting file runs **offline in any browser** without needing R, Shiny, or a network connection.
### Self-Contained vs. Lightweight Output Modes
* **`selfcontained = TRUE` (Default)**: Combines all React code, styling assets, and data base64 streams directly into a single `.html` file. Requires Pandoc to compile.
* **`selfcontained = FALSE`**: Recommended for large datasets or environments without Pandoc. It saves a lightweight `.html` file alongside a `_files/` companion directory containing the shared javascript and style sheets.
---
## 2. R Markdown (.Rmd) Document Integration
You can render `dtsmartr` interactive grids inline in any R Markdown HTML document.
Simply place the function inside standard code chunks. Set R Markdown chunk options (like `echo = FALSE` or `message = FALSE`) to suppress code display and warnings:
````markdown
---
title: "Clinical Analysis Report"
output: html_document
---
Below is the interactive labs analysis grid:
```{r, echo=FALSE, message=FALSE, warning=FALSE}
library(dtsmartr)
dtsmartr(mtcars)
```
````
When you knit the document, R Markdown compiles the widget as an interactive grid directly inline with your text.
---
## 3. Quarto (.qmd) Document Integration
Quarto supports `dtsmartr` natively out of the box. Add the code chunk using Quarto's standard syntax and comments:
````markdown
---
title: "Study Cohort Review"
format: html
---
## Laboratory Panel Exploration
Explore the interactive subject database:
```{r}
#| echo: false
#| message: false
#| warning: false
library(dtsmartr)
dtsmartr(mtcars)
```
````
When Quarto renders to HTML (`quarto render report.qmd`), the widget embeds inside the page container.
---
## 4. Downloadable Sample HTML Reports
To see what standalone HTML reports generated by `save_dtsmartr()` look and behave like offline, you can download these pre-compiled samples:
1. ๐ **[Download mtcars Sample HTML Report (mtcars_report.html)](https://wagh-nikhil.github.io/dtsmartr/samples/mtcars_report.html)** (Lightweight, self-contained single file)
2. ๐ **[Download ADSL Clinical Sample HTML Report (adsl_report.html)](https://wagh-nikhil.github.io/dtsmartr/samples/adsl_report.html)** (Lightweight clinical dataset: **306 rows ร 54 columns**, self-contained single file)
3. ๐งช **[Download ADLB Clinical Sample HTML Report (adlb_report.zip)](https://wagh-nikhil.github.io/dtsmartr/samples/adlb_report.zip)** (Standard clinical dataset: **83,652 rows ร 115 columns**, packaged as a ZIP containing the self-contained HTML file)
4. ๐ฌ **[Download Double-Sized ADLB Performance Report (adlb_large_report.zip)](https://wagh-nikhil.github.io/dtsmartr/samples/adlb_large_report.zip)** (Heavy clinical dataset: **167,304 rows ร 115 columns**, packaged as a ZIP containing the HTML and its assets folder for optimal load performance)
Simply download, unzip (for the zipped reports), open the `.html` file locally in any modern web browser, and test all scrolling, column anchoring, and reordering features offline!
---
## 5. Live Embedded Integration Preview
Here is an actual live rendering of `dtsmartr` embedded inside the R Markdown page container of this article, showing how it looks inside your generated reports:
```{r}
library(dtsmartr)
dtsmartr(mtcars)
```