SharedData

0th

Percentile

An R6 class that represents a shared data frame

...or sufficiently data frame-like object. The primary use for SharedData is to be passed to Crosstalk-compatible widgets in place of a data frame. Each SharedData$new(...) call makes a new "group" of widgets that link to each other, but not to widgets in other groups. You can also use a SharedData object from Shiny code in order to react to filtering and brushing from non-widget visualizations (like ggplot2 plots).

Keywords
datasets
Usage
SharedData
Format

An object of class R6ClassGenerator of length 25.

Constructor

SharedData$new(data, key = NULL, group = createUniqueId(4, prefix = "SharedData"))

data

A data frame-like object, or a Shiny reactive expression that returns a data frame-like object.

key

Character vector or one-sided formula that indicates the name of the column that represents the key or ID of the data frame. These must be unique, and ideally will be something intrinsic to the data (a proper ID) rather than a transient property like row index.

If NULL, then row.names(data) will be used.

group

The "identity" of the Crosstalk group that widgets will join when you pass them this SharedData object. In some cases, you will want to have multiple independent SharedData objects link up to form a single web of widgets that all share selection and filtering state; in those cases, you'll give those SharedData objects the same group name. (One example: in Shiny, ui.R and server.R might each need their own SharedData instance, even though they're intended to represent a single group.)

Methods

data(withSelection = FALSE, withFilter = TRUE, withKey = FALSE)

Return the data (or read and return the data if the data is a Shiny reactive expression). If withSelection, add a selection_ column with logical values indicating which rows are in the current selection, or NA if no selection is currently active. If withFilter (the default), only return rows that are part of the current filter settings, if any. If withKey, add a key_ column with the key values of each row (normally not needed since the key is either one of the other columns or else just the row names).

When running in Shiny, calling data() is a reactive operation that will invalidate if the selection or filter change (assuming that information was requested), or if the original data is a reactive expression that has invalidated.

origData()

Return the data frame that was used to create this SharedData instance. If a reactive expression, evaluate the reactive expression. Equivalent to data(FALSE, FALSE, FALSE).

groupName()

Returns the value of group that was used to create this instance.

key()

Returns the vector of key values. Filtering is not applied.

selection(value, ownerId = "")

If called without arguments, returns a logical vector of rows that are currently selected (brushed), or NULL if no selection exists. Intended to be called from a Shiny reactive context, and invalidates whenever the selection changes.

If called with one or two arguments, expects value to be a logical vector of nrow(origData()) length, indicating which rows are currently selected (brushed). This value is propagated to the web browser (assumes an active Shiny app or Shiny R Markdown document).

Set the ownerId argument to the outputId of a widget if conceptually that widget "initiated" the selection (prevents that widget from clearing its visual selection box, which is normally cleared when the selection changes). For example, if setting the selection based on a plotOutput brush, then ownerId should be the outputId of the plotOutput.

clearSelection(ownerId = "")

Clears the selection. For the meaning of ownerId, see the selection method.

Aliases
  • SharedData
Documentation reproduced from package crosstalk, version 1.1.0.1, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.