Description Usage Arguments Value Examples
The htmlwidgets package allows you to create R interfaces to javascript visualization code. The flexwidget package is a very basic widget that on its own does very little. Rather it sets up the widget so you can pass in custom javascript and html. See the vignette and examples for an illustration.
1 2 3 |
data |
data to pass to the js_code |
js_code |
javascript code, should be a function that takes in single argument, the data |
inner_html |
html to insert into the widget div |
resize |
javascript code for resizing, should be a function that takes in width and height argument. |
width |
width of widget, optional. Default is 100 percent |
height |
height of widget, optional |
elementId |
id for widget, optional |
dependencies |
javascript dependencies, should be list of html_dependency
objects created from |
an htmlwidget
1 2 3 4 5 6 7 8 9 10 11 12 | # Trivial example: creates an h1 div. passes the data multiplied by 2 to that div.
flexwidget(data = 2,
js_code = "function(data){document.getElementById('mydiv').textContent = data * 2}",
inner_html = htmltools::tags$h1(id = "mydiv"), height = "50px")
# Resize example
flexwidget(
resize = "function(width, height){document.getElementById('mydiv').textContent = width}",
inner_html = htmltools::tags$h1("Resize this window to get width", id = "mydiv2"),
height = "50px")
# For a plot example see vignette.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.