| Title: | 'SAS Studio'-Style Interactive Dataset Viewer |
|---|---|
| Description: | An interactive dataset viewer that renders a fast, scrollable grid with a column-selection panel, per-column property metadata, and a names-versus-labels header toggle, modelled on the 'SAS Studio' table viewer. Runs from one codebase in interactive 'Shiny' apps and in static HTML documents, with a free-text row filter, header sort, and CSV export, and handles large datasets without row sampling by querying them in the browser with 'DuckDB-WASM'. |
| Authors: | Vignesh Thanikachalam [aut, cre, cph] |
| Maintainer: | Vignesh Thanikachalam <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-07-09 14:27:41 UTC |
| Source: | https://github.com/cran/datasetviewer |
Renders a fast, scrollable data grid with a column-selection panel and per-column property metadata. The same widget renders in interactive Shiny apps and in static HTML documents.
dataset_viewer( x, ..., view = c("names", "labels"), width = NULL, height = NULL, elementId = NULL )dataset_viewer( x, ..., view = c("names", "labels"), width = NULL, height = NULL, elementId = NULL )
x |
Dataset to view. |
... |
Reserved for future arguments. |
view |
Initial header mode. |
width, height
|
Widget sizing. |
elementId |
Explicit DOM id. |
Query engine. The data is sent to the browser once as 'Parquet' and queried
in place with DuckDB-WASM, so filter, sort, and paging run over the whole
dataset with no row sampling. The engine (~35 MB) loads from a CDN by default
but is fetched into the package at install time when reachable, so a Shiny app
can serve it to browsers with no internet at runtime. Set
options(datasetviewer.use_local_engine = FALSE) to force the CDN (for small
self-contained HTML). See vignette("datasetviewer") for offline and
corporate deployment, including the DATASETVIEWER_DUCKDB_* install-time
environment variables.
An htmlwidget. Print it to render, or use it as a Shiny output.
Shiny bindings: datasetviewerOutput(), renderDatasetViewer().
# ---- Example 1: view a plain data frame ---- # # Wrap any data frame to get the interactive grid. Printing the widget in # an interactive session or a rendered document shows it; here we inspect # the payload so the example stays headless and self-contained (printing a # widget would launch a browser under R CMD check). viewer <- dataset_viewer(mtcars) viewer$x$n_rows # ---- Example 2: CDISC labels as headers ---- # # With the sibling artoo package, a CDISC-conformed frame supplies column # labels, formats, and storage lengths to the property pane and the # names-versus-labels header toggle. Start on labels with view = "labels". if (requireNamespace("artoo", quietly = TRUE)) { labelled <- dataset_viewer(artoo::cdisc_adsl, view = "labels") labelled$x$columns[[1]]$label }# ---- Example 1: view a plain data frame ---- # # Wrap any data frame to get the interactive grid. Printing the widget in # an interactive session or a rendered document shows it; here we inspect # the payload so the example stays headless and self-contained (printing a # widget would launch a browser under R CMD check). viewer <- dataset_viewer(mtcars) viewer$x$n_rows # ---- Example 2: CDISC labels as headers ---- # # With the sibling artoo package, a CDISC-conformed frame supplies column # labels, formats, and storage lengths to the property pane and the # names-versus-labels header toggle. Start on labels with view = "labels". if (requireNamespace("artoo", quietly = TRUE)) { labelled <- dataset_viewer(artoo::cdisc_adsl, view = "labels") labelled$x$columns[[1]]$label }
Output and render functions to embed dataset_viewer() in a Shiny app. The
widget pushes its live view state back to Shiny as inputs, so the app can
reuse the user's filter, sort, and column selection server-side.
datasetviewerOutput(outputId, width = "100%", height = "500px") renderDatasetViewer(expr, env = parent.frame(), quoted = FALSE)datasetviewerOutput(outputId, width = "100%", height = "500px") renderDatasetViewer(expr, env = parent.frame(), quoted = FALSE)
outputId |
Output slot id. |
width, height
|
CSS sizing. |
expr |
Render expression. A call that returns a |
env, quoted
|
Evaluation control. Standard htmlwidgets render plumbing; leave at their defaults. |
Inputs published. For an output with id "viewer" the widget sets, on
every change:
input$viewer_columns (<character>): selected column names.
input$viewer_filter (<character(1)>): the filter expression.
input$viewer_sort (<list>): sort keys (name, dir).
input$viewer_view (<character(1)>): "names" or "labels".
datasetviewerOutput() returns a Shiny output UI element;
renderDatasetViewer() returns a Shiny render function.
dataset_viewer() for the widget these bindings embed.
# ---- Example 1: read the viewer's filter and selection server-side ---- # # The app shows a dataset and echoes the filter expression and selected # columns the user builds in the grid. Runs only in an interactive session. if (interactive()) { library(shiny) ui <- fluidPage( datasetviewerOutput("viewer", height = "500px"), verbatimTextOutput("state") ) server <- function(input, output, session) { output$viewer <- renderDatasetViewer(dataset_viewer(mtcars)) output$state <- renderText({ paste0( "filter: ", input$viewer_filter, "\n", "columns: ", paste(input$viewer_columns, collapse = ", ") ) }) } shinyApp(ui, server) }# ---- Example 1: read the viewer's filter and selection server-side ---- # # The app shows a dataset and echoes the filter expression and selected # columns the user builds in the grid. Runs only in an interactive session. if (interactive()) { library(shiny) ui <- fluidPage( datasetviewerOutput("viewer", height = "500px"), verbatimTextOutput("state") ) server <- function(input, output, session) { output$viewer <- renderDatasetViewer(dataset_viewer(mtcars)) output$state <- renderText({ paste0( "filter: ", input$viewer_filter, "\n", "columns: ", paste(input$viewer_columns, collapse = ", ") ) }) } shinyApp(ui, server) }