flexwidget: Empty Widget for Custom Javascript

Description Usage Arguments Value Examples

View source: R/flexwidget.R

Description

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.

Usage

1
2
3
flexwidget(data = NULL, js_code = NULL, inner_html = NULL,
  resize = NULL, width = "100%", height = "100%", elementId = NULL,
  dependencies = NULL)

Arguments

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 htmlDependency

Value

an htmlwidget

Examples

 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.

AliciaSchep/flexwidget documentation built on May 7, 2019, 8:19 a.m.