gpanel: A panel to hold other JavaScript things

Description Usage Arguments Value Examples

View source: R/gpanel.R

Description

This produces a widget holding a "div" tag that other JavaScript libraries can use to place their content. There are a few reference class methods that make this possible. The div_id method returns the DOM id of the div object that is produced. The add_handler_onload method can be used to call a handler after the external libraries are loaded. This is an asynchronous call, so one need not worry that the libraries are done downloading. This call might require JavaScript commands to be processed that are not produced by a gWidgetsWWW2 handler. The add_js_queue method allows one to push such commands back to the browser. The method load_external is used to load external scripts by specifying the appropriate url(s).

Usage

1
gpanel(container, ..., width = NULL, height = NULL, ext.args = NULL)

Arguments

container

A parent container. In gWidgetsWWW2 a parent container is not optional (though it can be substituted with the parent argument in some circumstances). The parent specifies the widget heirarchy and the ... argument is used to pass along arguments to layout the child component in the parent container. Typically, these are passed to the add method of the parent container.

...

Used to pass along argument to the parent container's add method and possible other arguments to the underlying ference class constructors.

width

width in pixels of component. Sizing in gWidgetsWWW2 is sometimes necessary as the arguments expand and fill are not well implemented.

height

height in pixels of the component.

ext.args

The contructors of gWidgetsWWW2 ultimately call an Ext constructor. The options passed to the Ext constructor may be added to or overridden by use of this argument. Values are passed in as named list components and with values converted into JavaScript objects by asJSObject.

Value

a GPanel reference class object

Examples

 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
28
29
30
31
32
w <- gwindow("windows and dialogs")
g <- ggroup(cont=w, horizontal=FALSE)

pan <- gpanel(cont=g, width=200, height=200)
## will load d3 javascript library
d3_url <- "http://mbostock.github.com/d3/d3.js?2.7.1"
## template to simply insert HTML
## div_id comes from pan$div_id()
tpl <- "
function(data, status, xhr) {
  d3.select('#{{div_id}}').html('Look ma HTML');
}
"
## more complicated example to draw a line
tpl2 <- "
function(data, status, xhr) {
var chart = d3.select('#{{div_id}}').append('svg')
    .attr('class', 'chart')
    .attr('width', 200)
    .attr('height', 200);

chart.append('line')
    .attr('x1', 25)
    .attr('x2', 200 - 25)
    .attr('y1', 100)
    .attr('y2', 100)
    .style('stroke', '#000');
}
"

cmd <- whisker.render(tpl2, list(div_id=pan$div_id()))
pan$load_external(d3_url, cmd)

jverzani/gWidgetsWWW2 documentation built on Feb. 9, 2020, 5:18 p.m.