| perspective | R Documentation |
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
)
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"))
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.