rglShared: Create shared data from an RGL object

View source: R/rglwidget.R

rglSharedR Documentation

Create shared data from an RGL object

Description

The crosstalk package provides a way for different parts of an interactive display to communicate about datasets, using “shared data” objects. When selection or filtering is performed in one view, the result is mirrored in all other views.

This function allows vertices of RGL objects to be treated as shared data.

Usage

rglShared(id, key = NULL, group = NULL,
          deselectedFade = 0.1, 
          deselectedColor = NULL,
	  selectedColor = NULL,
          selectedIgnoreNone = TRUE,
	  filteredFade = 0,
          filteredColor = NULL)

Arguments

id

An existing RGL id.

key

Optional unique labels to apply to each vertex. If missing, numerical keys will be used.

group

Optional name of the shared group to which this data belongs. If missing, a random name will be generated.

deselectedFade, deselectedColor

Appearance of points that are not selected. See Details.

selectedColor

Appearance of points that are selected.

selectedIgnoreNone

If no points are selected, should the points be shown in their original colors (TRUE), or in the deselected colors (FALSE)?

filteredFade, filteredColor

Appearance of points that have been filtered out.

Details

Some functions which normally work on dataframe-like datasets will accept shared data objects in their place.

If a selection is in progress, the alpha value for unselected points is multiplied by deselectedFade. If deselectedColor is NULL, the color is left as originally specified; if not, the point is changed to the color given by deselectedColor.

If no points have been selected, then by default points are shown in their original colors. However, if selectedIgnoreNone = FALSE, all points are displayed as if unselected.

The selectedColor argument is similarly used to change the color (or not) of selected points, and filteredFade and filteredColor are used for points that have been filtered out of the display.

Value

An object of class "SharedData" (from the optional crosstalk package) which contains the x, y and z coordinates of the RGL object with the given id.

Author(s)

Duncan Murdoch

References

https://rstudio.github.io/crosstalk/index.html

Examples

  save <- options(rgl.useNULL = TRUE)
  
  #  rglShared requires the crosstalk package,
  #  and the slider and rglMouse require manipulateWidget
  
  if (requireNamespace("crosstalk", quietly = TRUE) &&
      requireNamespace("manipulateWidget", quietly = TRUE)) {
    open3d()
    x <- sort(rnorm(100))
    y <- rnorm(100)
    z <- rnorm(100) + atan2(x, y)
    ids <- plot3d(x, y, z, col = rainbow(100))

    # The data will be selected and filtered, not the axes.
    sharedData <- rglShared(ids["data"])
  
    # Also add some labels that are only displayed
    # when points are selected
  
    sharedLabel <- rglShared(text3d(x, y, z, text = 1:100,
                                    adj = -0.5),
                             group = sharedData$groupName(),
                             deselectedFade = 0,
                             selectedIgnoreNone = FALSE) 
    if (interactive() || in_pkgdown_example()) 
      crosstalk::filter_slider("x", "x", sharedData, ~x) %>%
      rglwidget(shared = list(sharedData, sharedLabel), controller = .) %>% 
      rglMouse()
  }    
  options(save)

rgl documentation built on Oct. 28, 2024, 5:07 p.m.