| Title: | Interactive Pivot Tables and Visualizations with 'Perspective' |
|---|---|
| Description: | An 'htmlwidgets' binding for the 'FINOS Perspective' <https://perspective-dev.github.io/> library, a high-performance 'WebAssembly'-powered data visualization engine. Provides interactive pivot tables, cross-tabulations, and multiple chart types (bar, line, scatter, heatmap, and more) that run entirely in the browser. Supports self-service analytics with drag-and-drop column selection, group-by/split-by pivoting, filtering, sorting, aggregation, and computed expressions. Works in 'RStudio' Viewer, 'R Markdown', 'Quarto', and 'Shiny' with streaming data updates via proxy interface. |
| Authors: | Eli Eydlin [aut, cre] |
| Maintainer: | Eli Eydlin <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 0.3.1 |
| Built: | 2026-05-14 05:41:42 UTC |
| Source: | https://github.com/eydlinilya/perspectiver |
Creates an interactive pivot table and visualization widget powered by the FINOS Perspective library. The viewer provides a self-service UI where users can interactively change chart types, group/split/filter/sort data, create computed columns, and configure aggregations.
perspective( data, columns = NULL, group_by = NULL, split_by = NULL, sort = NULL, filter = NULL, filter_op = NULL, expressions = NULL, aggregates = NULL, plugin = NULL, plugin_config = NULL, theme = "Pro Light", settings = TRUE, title = NULL, editable = FALSE, index = NULL, limit = NULL, use_arrow = FALSE, width = NULL, height = NULL, elementId = NULL )perspective( data, columns = NULL, group_by = NULL, split_by = NULL, sort = NULL, filter = NULL, filter_op = NULL, expressions = NULL, aggregates = NULL, plugin = NULL, plugin_config = NULL, theme = "Pro Light", settings = TRUE, title = NULL, editable = FALSE, index = NULL, limit = NULL, use_arrow = FALSE, width = NULL, height = NULL, elementId = NULL )
data |
A data.frame or matrix to display. |
columns |
Character vector of column names to show. If |
group_by |
Character vector of column names to group rows by (row pivots). |
split_by |
Character vector of column names to split columns by (column pivots). |
sort |
A list of two-element vectors, each containing a column name and
a direction ( |
filter |
A list of three-element vectors, each containing a column name,
an operator ( |
filter_op |
Character string controlling how multiple filters are
combined: |
expressions |
Character vector of Perspective expression strings for
computed columns. For example: |
aggregates |
A named list mapping column names to aggregate functions.
For example: |
plugin |
Character string specifying the visualization plugin.
Options include: |
plugin_config |
A list of plugin-specific configuration options. |
theme |
Character string specifying the CSS theme. Options:
|
settings |
Logical; whether to show the settings/configuration panel
sidebar. Default |
title |
Character string for the viewer title. If |
editable |
Logical; whether the data in the grid is user-editable.
Default |
index |
Character string naming a column to use as the table's primary
key. When set, |
limit |
Single positive integer specifying the maximum number of rows
the table will hold. When new rows are added beyond this limit, the oldest
rows are removed (rolling window). Mutually exclusive with |
use_arrow |
Logical; if |
width |
Widget width (CSS string or numeric pixels). |
height |
Widget height (CSS string or numeric pixels). |
elementId |
Optional explicit element ID for the widget. |
When used in a Shiny app, the following reactive inputs are available
(where outputId is the ID passed to perspectiveOutput):
input$<outputId>_configFires when the user changes the viewer configuration (columns, pivots, filters, etc.).
input$<outputId>_clickFires when the user clicks a cell or data point.
input$<outputId>_selectFires when the user selects rows or data points.
input$<outputId>_updateFires on each table data change
when subscribed via psp_on_update.
input$<outputId>_exportContains exported data after
calling psp_export.
input$<outputId>_stateContains saved viewer state after
calling psp_save.
input$<outputId>_schemaContains the table schema after
calling psp_schema.
input$<outputId>_sizeContains the table row count after
calling psp_size.
input$<outputId>_columnsContains the table column names
after calling psp_columns.
input$<outputId>_validate_expressionsContains expression
validation results after calling psp_validate_expressions.
An htmlwidgets object that can be printed, included in R Markdown, Quarto documents, or Shiny apps.
# Basic data grid perspective(mtcars) # Bar chart grouped by cylinder count perspective(mtcars, group_by = "cyl", plugin = "Y Bar") # Filtered and sorted view perspective(iris, columns = c("Sepal.Length", "Sepal.Width", "Species"), filter = list(c("Species", "==", "setosa")), sort = list(c("Sepal.Length", "desc")) )# Basic data grid perspective(mtcars) # Bar chart grouped by cylinder count perspective(mtcars, group_by = "cyl", plugin = "Y Bar") # Filtered and sorted view perspective(iris, columns = c("Sepal.Length", "Sepal.Width", "Species"), filter = list(c("Species", "==", "setosa")), sort = list(c("Sepal.Length", "desc")) )
Creates a Perspective viewer output element for use in a Shiny UI.
perspectiveOutput(outputId, width = "100%", height = "400px")perspectiveOutput(outputId, width = "100%", height = "400px")
outputId |
Output variable name. |
width |
CSS width (default |
height |
CSS height (default |
The following reactive inputs are available (where outputId is the
ID you supply):
input$<outputId>_configViewer configuration changes.
input$<outputId>_clickCell/data-point click events.
input$<outputId>_selectRow/data-point selection events.
input$<outputId>_updateTable data changes (requires
psp_on_update).
input$<outputId>_exportExported data (after
psp_export).
input$<outputId>_stateSaved viewer state (after
psp_save).
input$<outputId>_schemaTable schema (after
psp_schema).
input$<outputId>_sizeTable row count (after
psp_size).
input$<outputId>_columnsTable column names (after
psp_columns).
input$<outputId>_validate_expressionsExpression validation
results (after psp_validate_expressions).
A Shiny output element.
if (interactive()) { library(shiny) ui <- fluidPage( perspectiveOutput("viewer", height = "600px") ) }if (interactive()) { library(shiny) ui <- fluidPage( perspectiveOutput("viewer", height = "600px") ) }
Creates a proxy object that can be used to update an existing Perspective
viewer in a Shiny app without re-rendering the entire widget. Use this with
psp_update, psp_replace, psp_clear, psp_restore,
and psp_reset to modify the viewer.
perspectiveProxy(session, outputId)perspectiveProxy(session, outputId)
session |
The Shiny session object (usually |
outputId |
The output ID of the Perspective widget to control. |
A proxy object of class "perspective_proxy".
if (interactive()) { server <- function(input, output, session) { output$viewer <- renderPerspective({ perspective(mtcars) }) observeEvent(input$add_data, { proxy <- perspectiveProxy(session, "viewer") psp_update(proxy, new_data) }) } }if (interactive()) { server <- function(input, output, session) { output$viewer <- renderPerspective({ perspective(mtcars) }) observeEvent(input$add_data, { proxy <- perspectiveProxy(session, "viewer") psp_update(proxy, new_data) }) } }
Removes all rows from the Perspective table (schema is preserved).
psp_clear(proxy)psp_clear(proxy)
proxy |
A |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_clear(proxy) }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_clear(proxy) }
Requests the column names of the Perspective table. The result is
delivered asynchronously to input$<outputId>_columns.
psp_columns(proxy)psp_columns(proxy)
proxy |
A |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_columns(proxy) }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_columns(proxy) }
Requests data export from the current Perspective view. The result is
delivered asynchronously to input$<outputId>_export.
psp_export( proxy, format = c("json", "csv", "columns", "arrow"), start_row = NULL, end_row = NULL, start_col = NULL, end_col = NULL )psp_export( proxy, format = c("json", "csv", "columns", "arrow"), start_row = NULL, end_row = NULL, start_col = NULL, end_col = NULL )
proxy |
A |
format |
Export format: |
start_row |
Optional single numeric value specifying the first row (0-based) to include in the export. |
end_row |
Optional single numeric value specifying the row (0-based, exclusive) at which to stop. |
start_col |
Optional single numeric value specifying the first column (0-based) to include. |
end_col |
Optional single numeric value specifying the column (0-based, exclusive) at which to stop. |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_export(proxy, format = "csv") }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_export(proxy, format = "csv") }
Enables or disables a subscription to table data changes. When enabled,
every table.update() triggers input$<outputId>_update
with a list containing timestamp, port_id, and
source ("edit" for user edits, "api" for
programmatic updates).
psp_on_update(proxy, enable = TRUE)psp_on_update(proxy, enable = TRUE)
proxy |
A |
enable |
Logical; |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_on_update(proxy) }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_on_update(proxy) }
Removes rows matching the given primary-key values from an indexed
Perspective table. The table must have been created with an index
column (see perspective).
psp_remove(proxy, keys)psp_remove(proxy, keys)
proxy |
A |
keys |
A vector of key values identifying the rows to remove. |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_remove(proxy, keys = c("row1", "row2")) }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_remove(proxy, keys = c("row1", "row2")) }
Replaces the entire dataset in the Perspective table.
psp_replace(proxy, data, use_arrow = FALSE)psp_replace(proxy, data, use_arrow = FALSE)
proxy |
A |
data |
A data.frame containing the replacement data. |
use_arrow |
Logical; use Arrow IPC serialization. Default |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_replace(proxy, updated_data) }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_replace(proxy, updated_data) }
Resets the Perspective viewer to its default configuration.
psp_reset(proxy)psp_reset(proxy)
proxy |
A |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_reset(proxy) }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_reset(proxy) }
Applies a configuration object to the Perspective viewer, changing columns, group_by, split_by, filters, sort, aggregates, plugin, etc.
psp_restore(proxy, config)psp_restore(proxy, config)
proxy |
A |
config |
A list of Perspective viewer configuration options. |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_restore(proxy, list(plugin = "Y Bar", group_by = list("cyl"))) }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_restore(proxy, list(plugin = "Y Bar", group_by = list("cyl"))) }
Requests the current viewer configuration (columns, pivots, filters, sort,
plugin, etc.). The result is delivered asynchronously to
input$<outputId>_state.
psp_save(proxy)psp_save(proxy)
proxy |
A |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_save(proxy) }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_save(proxy) }
Requests the schema (column names and types) of the Perspective table.
The result is delivered asynchronously to input$<outputId>_schema.
psp_schema(proxy)psp_schema(proxy)
proxy |
A |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_schema(proxy) }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_schema(proxy) }
Requests the number of rows in the Perspective table. The result is
delivered asynchronously to input$<outputId>_size.
psp_size(proxy)psp_size(proxy)
proxy |
A |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_size(proxy) }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_size(proxy) }
Sends new rows to be appended to the existing Perspective table.
psp_update(proxy, data, use_arrow = FALSE)psp_update(proxy, data, use_arrow = FALSE)
proxy |
A |
data |
A data.frame of new rows to append. |
use_arrow |
Logical; use Arrow IPC serialization. Default |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_update(proxy, new_data) }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_update(proxy, new_data) }
Validates Perspective expression strings against the table without
applying them. The result is delivered asynchronously to
input$<outputId>_validate_expressions.
psp_validate_expressions(proxy, expressions)psp_validate_expressions(proxy, expressions)
proxy |
A |
expressions |
A non-empty character vector of expression strings. |
The proxy object (invisibly), for chaining.
if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_validate_expressions(proxy, expressions = c("\"col1\" + \"col2\"")) }if (interactive()) { proxy <- perspectiveProxy(session, "viewer") psp_validate_expressions(proxy, expressions = c("\"col1\" + \"col2\"")) }
Server-side rendering function for the Perspective widget.
renderPerspective(expr, env = parent.frame(), quoted = FALSE)renderPerspective(expr, env = parent.frame(), quoted = FALSE)
expr |
An expression that returns a |
env |
The environment in which to evaluate |
quoted |
Logical; is |
A Shiny render function.
if (interactive()) { server <- function(input, output) { output$viewer <- renderPerspective({ perspective(mtcars, group_by = "cyl", plugin = "Y Bar") }) } }if (interactive()) { server <- function(input, output) { output$viewer <- renderPerspective({ perspective(mtcars, group_by = "cyl", plugin = "Y Bar") }) } }
Launches a bundled Shiny example app demonstrating the perspectiveR widget.
run_example(example = NULL, ...)run_example(example = NULL, ...)
example |
Name of the example to run. Use |
... |
Additional arguments passed to |
If example is NULL, a character vector of available
example names (invisibly). Otherwise, no return value; called for the side
effect of launching a Shiny app.
# List available examples run_example() # Launch the demo app if (interactive()) { run_example("shiny-basic") }# List available examples run_example() # Launch the demo app if (interactive()) { run_example("shiny-basic") }