Learn R Programming

fsbrain (version 0.6.0)

vis.rglwidget: Visualize coloredmeshes as an interactive rgl WebGL widget for use in R Shiny apps and RMarkdown documents.

Description

Create an interactive 3D brain view that can be embedded in R Shiny applications or RMarkdown/HTML documents. Unlike the standard vis.* functions which open an X11/OpenGL window and are designed for static screenshot export, this function renders to a headless rgl device and returns an rglwidget object that provides interactive 3D rendering in a web browser. The user can rotate, zoom, and pan the brain in the widget.

Usage

vis.rglwidget(
  coloredmeshes,
  background = "white",
  skip_all_na = TRUE,
  style = "default",
  rgloptions = rglo(),
  ...
)

Value

an htmlwidget object from the rgl package, suitable for use with rglwidgetOutput / renderRglwidget in Shiny, or for direct embedding in RMarkdown HTML output.

Arguments

coloredmeshes,

a hemilist of coloredmeshes (as returned by vis.subject.morph.native and similar functions when called with rglactions=list('no_vis'=TRUE)) or a flat list of coloredmesh instances.

background

string, background color passed to bg3d. Defaults to "white".

skip_all_na

logical, whether to skip (i.e., not render) meshes in the list that have the property 'render' set to FALSE. Defaults to TRUE.

style,

a named list of style parameters or a string specifying an available style by name (e.g., 'shiny'). Defaults to 'default', the default style.

rgloptions,

named list. Parameters passed to par3d. Defaults to the value returned by rglo.

...

extra arguments passed to rglwidget.

See Also

Other visualization functions: highlight.vertices.on.subject(), highlight.vertices.on.subject.spheres(), vis.color.on.subject(), vis.data.on.fsaverage(), vis.data.on.subject(), vis.labeldata.on.subject(), vis.mask.on.subject(), vis.region.values.on.subject(), vis.subject.annot(), vis.subject.label(), vis.subject.morph.native(), vis.subject.morph.standard(), vis.subject.pre(), vis.symmetric.data.on.subject(), vis.volume.on.surface(), vislayout.from.coloredmeshes()

Examples

Run this code
if (FALSE) {
   fsbrain::download_optional_data();
   fsbrain::download_fsaverage(accept_freesurfer_license=TRUE);
   subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir");

   # Get coloredmeshes without opening a window:
   cm = vis.subject.annot(subjects_dir, 'subject1', 'aparc', 'both',
         rglactions=list('no_vis'=TRUE));

   # Create an interactive WebGL widget:
   widget = vis.rglwidget(cm);

   # In RMarkdown, just print it:
   # widget

   # In Shiny, use rglwidgetOutput / renderRglwidget (see the shiny demo app).
}

Run the code above in your browser using DataLab