Writes the current scene to a collection of files that contain WebGL code to reproduce it in a browser.
1 2 3 4 5
Where to write the files.
The filename to use for the main file.
Whether to include a snapshot of the scene, to be displayed in browsers that don't support WebGL, or a specification of the snapshot to use. See details below.
Whether to include parts that would be common to several figures on the same page. Currently this includes a reference to and copy of the ‘CanvasMatrix.js’ file in the output.
When writing several figures on the same page, set this to a dataframe containing values to reuse. See the Value section below.
The font to use for text.
The (optional) width and height in pixels of the image to display. If omitted,
template argument to give the filename of a web page that is to contain the
code for the new scene. It should contain a single line containing
paste0("%", prefix, "WebGL%"), e.g.
code necessary to reproduce the current scene. The template may also contain the string
which will be replaced with the current rgl version number. If
NULL, the output will simply be written directly
to the main file.
To put more than one scene into a web page, use different values of
prefix for each. The prefix
only use alphanumeric characters.
WebGL is a fairly new technology for displaying 3D scenes in browsers. Most current browsers support it to some extent, though it may not be enabled by default; see http://get.webgl.org for details. A major exception currently is Microsoft's Internet Explorer, though plugins are available.
writeWebGL has a number of known limitations, some of which will be gradually eliminated as
The bounding box decorations are fixed; labels do not move as they do within R.
User-defined mouse controls are not supported.
Missing values are not handled properly.
WebGL browsers generally do not support more than 65535 vertices per
writeWebGL will print a warning if this limit is exceeded, but it is up to the user
to break his scene into smaller objects. (And 65535 vertices may not be small enough!)
filename is returned. If
reuse is not
it will have an attribute called
"reuse" which contains a dataframe
"prefix" identifying the prefix used
for objects drawn in this scene. This dataframe can be used as the
argument in subsequent calls to
This function is deprecated in favour of the
TRUE, the output includes a binary copy of
function properly, but only one copy is needed if the output page
Its source (including
the copyright notice and license for free use) is included in the file named by
system.file("htmlwidgets/lib/CanvasMatrix.src.js", package = "rgl").
1 2 3 4 5 6 7 8 9 10
plot3d(rnorm(100), rnorm(100), rnorm(100), type = "s", col = "red") # This writes a copy into temporary directory 'webGL', and then displays it filename <- writeWebGL(dir = file.path(tempdir(), "webGL"), width = 500, reuse = TRUE) # Display the "reuse" attribute attr(filename, "reuse") # Display the scene in a browser if (interactive()) browseURL(paste0("file://", filename))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.