playwidget | R Documentation |
This is a widget that can be put in a web page to allow animations with or without Shiny.
playwidget(sceneId, controls,
start = 0, stop = Inf, interval = 0.05, rate = 1,
components = c("Reverse", "Play", "Slower", "Faster",
"Reset", "Slider", "Label"),
loop = TRUE,
step = 1, labels = NULL,
precision = 3,
elementId = NULL, respondTo = NULL,
reinit = NULL,
buttonLabels = components, pause = "Pause",
height = 40,
...)
sceneId |
The HTML id of the RGL scene being controlled, or an object. See the Details below. |
controls |
A single |
start , stop |
The starting and stopping values of the animation. If
|
interval |
The requested interval (in seconds) between updates. Updates may occur at longer intervals. |
rate |
The number of units of “nominal” time per real world second. |
components |
Which components should be displayed? See Details below. |
loop |
When the player reaches the end of the interval, should it loop back to the beginning? |
step |
Step size in the slider. |
labels |
Optional labels to use, corresponding to slider steps. Set to
|
precision |
If |
elementId |
The HTML id of the generated widget, containing buttons, slider, etc. |
respondTo |
The HTML ID of a Shiny input control (e.g. a |
reinit |
A vector of ids that will need re-initialization before being drawn again. |
buttonLabels , pause |
These are the labels that will be shown on the buttons if they are displayed. |
height |
The height of the widget in pixels. In a pipe, this is a relative height. |
... |
Additional arguments to pass to
to |
The components
are buttons to control the animation,
a slider for manual control, and a label to show the current
value. They will be displayed in the order given in components
. Not all need be included.
The buttons have the following behaviour:
Reverse the direction.
Play the animation.
Decrease the playing speed.
Increase the playing speed.
Stop the animation and reset to the start value.
If respondTo
is used, no components
are shown, as it is assumed Shiny (or whatever control is being referenced) will provide the UI components.
The sceneId
component can be another playwidget
, a rglwidget
result, or a result of
htmltools::tags
or htmltools::tagList
. This allows you
to use a magrittr-style
“pipe” command to join an rglwidget
with one or more playwidget
s. If a playwidget
comes
first, sceneId
should be set to NA
. If
the rglwidget
does not come first,
previous values should be piped into its controllers
argument. Other HTML code (including other widgets)
can be used in the chain if wrapped in htmltools::tagList
.
Each control should inherit from "rglControl"
. They
can have the following components in addition to any
private ones:
labels
default labels for the slider.
param
values to include on the slider.
dependencies
additional HTML dependencies to
include, after the default rglwidgetClass
.
A widget suitable for use in an Rmarkdown-generated web page, or elsewhere.
The appearance of the controls is set by the stylesheet
in system.file("htmlwidgets/lib/rglClass/rgl.css")
.
The overall widget is of class rglPlayer
, with id
set according to elementId
.
The buttons are of HTML class rgl-button
, the
slider is of class rgl-slider
, and the label is of
class rgl-label
. Each element has an id prefixed
by the widget id, e.g. elementId-button-Reverse
,
elementId-slider
, etc. (where elementId
should be replaced by the actual id).
The reinit
parameter handles the case where
an object needs re-initialization after each change. For
example, plane objects may need this if their intersection
with the bounding box changes shape. Note that
re-initialization is generally incompatible with
the vertexControl
as it modifies values
which are set during initialization.
Duncan Murdoch
subsetControl
,
propertyControl
, ageControl
and
vertexControl
are possible controls to use.
toggleWidget
is a wrapper for
playwidget
and subsetControl
to insert a single button to toggle some elements in a display.
saveopts <- options(rgl.useNULL = TRUE)
objid <- plot3d(1:10, 1:10, rnorm(10), col=c("red", "red"), type = "s")["data"]
control <- ageControl(value=0,
births=1:10,
ages = c(-5,0,5),
colors = c("green", "yellow", "red"),
objids = objid)
# This example uses explicit names
rglwidget(elementId = "theplot", controllers = "theplayer",
height = 300, width = 300)
playwidget("theplot", control, start = -5, stop = 5,
rate = 3, elementId = "theplayer",
components = c("Play", "Slider"))
# This example uses pipes, and can skip the names
widget <- rglwidget(height = 300, width = 300) %>%
playwidget(control, start = -5, stop = 5,
rate = 3, components = c("Play", "Slider"))
if (interactive() || in_pkgdown_example())
widget
options(saveopts)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.