Description Usage Arguments Value Author(s) See Also Examples
This function facilitates inserting D3 (JavaScript) code
into an HTML document.
The JavaScript code is typically
generated by d3Device
and the R graphics engine.
The function also allows us to add additional supporting JavaScript code
and CSS content.
1 2 3 4 5 | addToHTMLTemplate(code, outfile = character(),
supportCode = system.file("JavaScript", "Plot.js", package = "RD3Device"),
html = system.file("template", "template.html", package = "RD3Device"),
css = character(), div = "svg",
isFile = length(code) == 1 && file.exists(code))
|
code |
a character vector containing the JavaScript code or the name of a file containing the JavaScript code. |
outfile |
the name of the file to which the HTML document will be written. This is different from the template file. |
supportCode |
the names of one or more JavaScript files which should also be included in the HTML document. These are intended for supporting code that defines classes and functions used by the JavaScript D3 code to creat the display. |
html |
the name of the template HTML document which we fill in |
css |
the name of a CSS file or the actual contents of the CSS.
If specified, the contents are inserted into the |
div |
the identifier (id) of the HTML element (typically a
|
isFile |
a logical value that indicates whether |
If out
is not empty, the name of the resulting file.
If out
is empty, the contents of the HTML document
as a parsed tree.
Duncan Temple Lang
1 2 3 4 5 6 7 8 9 10 11 12 | dev = d3Device()
with(mtcars, plot(wt, mpg))
abline(fit <- lm(mpg ~ wt, mtcars), lty = 2, col = "red")
dev.off()
code = dev$getCode()
cir = names(code) == "circle"
code[cir] = mapply(function(code, id) {
c(code, sprintf("el.append(\"svg:title\").text(\"%s\");", id))
}, code[cir], rownames(mtcars), SIMPLIFY = FALSE)
addToHTMLTemplate(code, "mtcars.html")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.