Description Usage Arguments Value Author(s) References See Also Examples
This function opens a new R graphics device and becomes the active device to which graphics commands are sent. This device maps the graphical commands to JavaScript code. When the device is closed, the JavaScript is either written to a file or made available as a character vector. This JavaScript code can then be added to an HTML document and rendered on a JavaScript canvas.
1 2 3 4 |
file |
the name of a file or a connection object to which the generated JavaScript code will be written when the device is closed. This can be an empty vector (the default) in which case the code is not written to a file. Instead, the code can be accessed from the device. This argument can also be an R call or expression and it will be evaluated and the resulting JavaScript code returned directly. This allows one to open, plot and close the device in a single action and retrieve the JavaScript code in one operation. |
dim |
the dimensions to use for the HTML canvas device. These are pixels. |
col |
the default drawing color |
fill |
the default fill color |
ps |
the initial point size |
wrapup |
a function that is invoked when the device is closed.
This is called with a list of containing code for each of the
separate "pages" created in R, i.e. each time we call NewFrame.
The content of each element of the page list is a character vector
containing the JavaScript code for that page.
The second argument is the file or connection to which to write the
generated JavaScript code. Additional parameters passed to
|
canvasId |
the identifier(s) (i.e. name(s)) of the canvases on which to draw. |
multiCanvas |
a logical value that controls whether the functions
arrange to draw on the separate canvases for each plot ( |
... |
additional arguments that are passed on to the function
specified by |
runPlotCommand |
this is a logical value that controls whether to
interpret the |
If runPlotCommand
is TRUE
(e.g. if one passes a
non-literal value for file
), a charcter vector
containing the generated JavaScript code is returned.
Otherwise, an object of class JavaScriptCanvasDevice
is returned. This contains a reference to the C-level
data structure representing the device and one can access
the fields in the device and the R functions that implement
the device.
Duncan Temple lang
R Internals Manual for details on graphics devices.
The RGraphics 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 25 26 27 | js.code = jsCanvas({ plot(1:10); plot(density(rnorm(100)))})
dev = jsCanvas()
plot(1:10)
plot(density(rnorm(100)))
f = getCode(dev) # currently need to return the function before device is closed
dev.off()
f()
jsCanvas("myJSCode.js")
plot(1:10)
plot(density(rnorm(100)))
dev.off()
# This version writes to a file, but also controls the name of the
# javascript functions - myPlot1 and myPlot2 - and arranges that
# each of them is to draw on the canvas named plotCanvas.
# We can then call these JavaScript functions at different times and
# they will draw on that canvas.
# We also inline the supporting JavaScript code.
jsCanvas("myJSCode.js", funName = "myPlot", canvasId = 'plotCanvas',
multiCanvas = FALSE, inlineJS = TRUE)
plot(1:10)
plot(density(rnorm(100)))
dev.off()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.