Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

gtable

A constructor for displaying tabular data for selection


Description

The tabular widget allows a user to select one (or more) row(s) using the mouse or keyboard selection. The selected rows are the main property and are returned by svalue through their key (from the column specified by chosen.col), or by index. The change handler changes on double-click event. Use add handler click to respond to a change in selection.

.gtable generic for toolkit dispatch

For gtable one can pass in row(s) to select by index (when index=TRUE) or by match among the values in the chosen column. For setting by index, a value of 0L or integer(0) will clear the current selection

For GTable objects the [ and [<- methods are (mostly) implemented. The [ method allows one to access the object using the regular matrix notation (but there is no list notation, e.g. $ or [[, defined). The [<- method is available, but for most toolkits is restricted: one can not add columns, add rows, remove columns, remove rows, or change the type of the column. For all of these actions, one can reassign the items being displayed through the idiom obj[] <- new_items. This allows the widget to resize or redo the column renderers.

The change handler for GTable is called when the selection changes. This is often the result of a click event (but need not be), although we alias to addHandlerClicked. For double click events, see addHandlerDoubleclick.

Double clicking is used to activate an item (single click is selection). We also bind pressing the Return key on an item to initiate this signal

For GTable, visibility refers to which rows are currently shown, not whether the widget itself is shown or hidden. (For the latter, place the widget into a container and adjust that). One can use this method to perform filtering by adjusting which rows are displayed according to some criteria that returns a logical.

For GTable the size<- method is overridden to allow one to specify the column widths. To do so, pass in the values for width, height or column.widths as named components of a list. The value of column.widths should be a numeric vector of pixel widths of length matching the number of columns.

Usage

gtable(items, multiple = FALSE, chosen.col = 1, icon.col = NULL,
  tooltip.col = NULL, handler = NULL, action = NULL, container = NULL,
  ..., toolkit = guiToolkit())

.gtable(toolkit, items, multiple = FALSE, chosen.col = 1, icon.col = NULL,
  tooltip.col = NULL, handler = NULL, action = NULL, container = NULL,
  ...)

## S3 method for class 'GTable'
svalue(obj, index = NULL, ..., value)

## S3 method for class 'GTable'
x[i, j, ..., drop = TRUE]

## S3 method for class 'GTable'
addHandlerChanged(obj, handler, action = NULL, ...)

## S3 method for class 'GTable'
addHandlerDoubleclick(obj, handler, action = NULL, ...)

## S3 method for class 'GTable'
visible(obj, ...)

## S3 replacement method for class 'GTable'
 size(obj) <- value

Arguments

items

data.frame specifies items for selection. May be a vector, matrix or data frame

multiple

logical allow multiple selection

chosen.col

which value from the row is returned by selection

icon.col

NULL or integer. If latter, specifies column containing stock icon

tooltip.col

NULL or integer. If latter, specifies column containing tooltip

handler

A handler assigned to the default change signal. Handlers are called when some event triggers a widget to emit a signal. For each widget some default signal is assumed, and handlers may be assigned to that through addHandlerChanged or at construction time. Handlers are functions whose first argument, h in the documentation, is a list with atleast two components obj, referring to the object emitting the signal and action, which passes in user-specified data to parameterize the function call.

Handlers may also be added via addHandlerXXX methods for the widgets, where XXX indicates the signal, with a default signal mapped to addHandlerChanged (cf. addHandler for a listing). These methods pass back a handler ID that can be used with blockHandler and unblockHandler to suppress temporarily the calling of the handler.

action

User supplied data passed to the handler when it is called

container

A parent container. When a widget is created it can be incorporated into the widget heirarchy by passing in a parent container at construction time. (For some toolkits this is not optional, e.g. gWidgets2tcltk or gWidgets2WWW2.)

...

These values are passed to the add method of the parent container. Examples of values are expand, fill, and anchor, although they're not always supported by a given widget. For more details see add. Occasionally the variable arguments feature has been used to sneak in hidden arguments to toolkit implementations. For example, when using a widget as a menubar object one can specify a parent argument to pass in parent information, similar to how the argument is used with gaction and the dialogs.

toolkit

Each widget constructor is passed in the toolkit it will use. This is typically done using the default, which will lookup the toolkit through guiToolkit.

obj

object of method call

index

NULL or logical. If TRUE and widget supports it an index, instead of a value will be returned.

value

value to assign for selection or property

x

GTable object

i

row index

j

column index

drop

do we drop when subsetting

Details

Many generic methods for data frames are implemented for gtable. These include [, [<-, length, names, and names<-

Value

Returns an object of class GTable

Examples

## Not run: 
w <- gwindow("gtable example", visible=FALSE)
g <- gvbox(cont=w)
tbl <- gtable(mtcars, cont=g, expand=TRUE, fill=TRUE)
addHandlerClicked(tbl, handler=function(h,...) sprintf("You selected %s", svalue(h$obj)))
visible(w) <- TRUE


## End(Not run)

gWidgets2

Rewrite of gWidgets API for Simplified GUI Construction

v1.0-8
GPL (>= 3)
Authors
John Verzani
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.