Description Usage Arguments Details Value Author(s) References Examples
This function allows the canvas package to create a javascript device. Although this isn't working with all browsers, it does work quite well with firefox.
1 |
f |
optional filename storing canvas output |
width |
width of canvas in pixels |
height |
height of canvas in pixels |
container |
parent container for processing object |
... |
not used |
Jeffrey Horner's canvas package provides a javascript implementation of an R device. The use if very similar to
a regular, non-interactive R device, such as png
. The gcanvas
widget provides the screen space
to display the graphic.
The svalue<-
method is used to update the graphic. By default
the background color for a canvas device is transparent, so graphs
will layer on top of each other. To avoid this, specify a background
color using hex notation, e.g., bg="#ffffff"
for white.
Only one gcanvas
widget can be used in a GUI, as underlying
the canvas
javascript is a fixed variable name. This includes
subwindows of a GUI, so this is a poor choice for using in a window
that can be dismissed and re-opened.
Both the gcanvas
constructor and the
canvas
device have width and height arguments. These should be
the same, but it is up to the user to ensure this.
This replaces the gprocessingjs
widget that isn't working as of version 0.8.0
Returns a proto object with class gCanvas.
John Verzani
The canvas device package
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ## Not run:
require(canvas, quietly=TRUE, warn=FALSE) ## require quietly
## Make a simple graph
f <- tempfile() ## A file to store the javascript code
canvas(file=f, width=480, height=400)
hist(rnorm(100))
dev.off() ## write javascript code to f
w <- gwindow("Canvas test")
g <- ggroup(cont = w, horiz=F)
cv <- gcanvas(f,cont = g) ## when f is given, graph an initial graph
## is drawn
## How to update the graphic using the svalue method
b <- gbutton("click me", cont = g, handler = function(h,...) {
canvas(file=f, width=480, height=400, bg="#ffffff") ## specify a
## background color
hist(rexp(100))
dev.off()
svalue(cv) <- f
})
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.