Learn R Programming

gWidgets2 (version 1.0-9)

gradio: Constructor for radio button widget

Description

A radio button group allows a user to select one from many items. In gWidgets2 the radio button widget shows 2 or more items. The items are coerced to characters, usually by the underlying toolkit. Use the coerce_with property to set a function, such as as.numeric, to coerce the return value during the svalue code. The items are referred to with the [ method, the selected one with svalue.

The svalue method returns the radio button label or its index if index=TRUE. Labels are coerced to character by many of the toolkits. To be sure to return a numeric value, one can assign to the coerce_with property, e.g., obj$coerce_with <- as.numeric. For all widgets, if a function is specified to coerce_with it will be called on the value returned by svalue.

For a radio button group, for svalue the value can be referred to by index or label.

Check for repeated items before passing on to set_items

Usage

gradio(
  items,
  selected = 1,
  horizontal = FALSE,
  handler = NULL,
  action = NULL,
  container = NULL,
  ...,
  toolkit = guiToolkit()
)

.gradio( toolkit, items, selected = 1, horizontal = FALSE, handler = NULL, action = NULL, container = NULL, ... )

# S3 method for GRadio svalue(obj, index = NULL, drop = TRUE, ...)

# S3 method for GRadio svalue (obj,index=NULL,drop=TRUE,...) <- value

# S3 method for GRadio [ (x, i, j, ...) <- value

Arguments

items

items to select from

selected

index of initially selected item

horizontal

layout direction

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.

drop

NULL or logical. If widget supports it, drop will work as it does in a data frame or perhaps someother means.

value

items to assigns a choices for the buttons

x

GRadio object

i

button index. Leavel as missing to replace items to select from.

j

ignored

Examples

Run this code
# NOT RUN {
if(interactive()) {
  w <- gwindow("Selection widgets")
  g <- gvbox(cont=w)

  fl <- gformlayout(cont=g)
  gcheckbox("checkbox", checked=TRUE, cont=fl, label="checkbox")
  gradio(state.name[1:4], selected=2, horizontal=TRUE, cont=fl, label="gradio")
  gcheckboxgroup(state.name[1:4], horizontal=FALSE, cont=fl, label="checkbox group")

  bg <- ggroup(cont=g)
  gbutton("ok", cont=bg, handler=function(h,...) print(sapply(fl$children, svalue)))



}
# }

Run the code above in your browser using DataLab