rp.listbox: Listbox for a panel

View source: R/listbox.r

rp.listboxR Documentation

Listbox for a panel

Description

This function adds a listbox to the panel. When an item is pressed, a variable is set and an action function is called.

Usage

rp.listbox(panel, variable, vals, labels = vals,
           rows=length(labels), initval=vals[1], pos=NULL, 
           title=deparse(substitute(variable)), action=I, foreground=NULL,
           background=NULL, font=NULL, parentname=deparse(substitute(panel)),
           sleep = 0.01, name=paste("listbox", .nc(), sep=""), ...)

Arguments

panel

the panel in which the listbox should appear.

variable

the name of the variable whose value is set by the listbox.

vals

the values of var used by the listbox. NOTE: Not currently in use, intended to be.

labels

the labels for values of var offered by the listbox.

rows

the number of rows in the list. This defaults to the number of labels. If the number of labels is greater than the number of rows the listbox will be displayed with a scrollbar.

initval

the initial value of <var> (optional). The initial value can also be specified in the call to rp.control.

pos

the layout instructions. Please see the rp.pos example and help for full details.

title

the label for the listbox.

action

the function which is called when an item is chosen.

foreground

colour of the text

background

colour of the text background

font

font to be used

parentname

this specifies the widget inside which the listbox should appear.

sleep

a length of time in seconds, passed to Sys.sleep, which can be used to overcome a technical problem in some computer systems. If the listbox appears blank, then setting this parameter to a slightly value may fix the problem.

name

name assigned to the listbox, used for disposing of the widget

...

...

Details

The function action should take one argument, which should be the panel to which the listbox is attached.

See rp.grid for details of the grid layout system.

Value

If the argument panel is the panelname string, the same string is returned. If the panel object is used, the altered panel is assigned to both the calling level and panel's environment level.

Warning

The action function should return the panel. Without this assignment any widgets added or alterations made to panel parameters within the action function will be lost.

Note

The former arguments parent and ... have been discontinued in version 1.1. Note also that the argument var has been renamed variable to avoid reserved word issues.

References

rpanel: Simple interactive controls for R functions using the tcltk package. Journal of Statistical Software, 17, issue 9.

See Also

rp.checkbox,rp.control

Examples

## Not run: 
   data.plotfn <- function(panel) {
     if (panel$plot.type == "histogram")
       hist(panel$x)
     else
       if (panel$plot.type == "boxplot")
         boxplot(panel$x)
       else
         plot(density(panel$x))
     panel
   }
   panel <- rp.control(x = rnorm(50))
   rp.listbox(panel, plot.type,
       c("histogram", "boxplot", "density estimate"),
       action = data.plotfn, title = "Plot type") 

## End(Not run)

rpanel documentation built on Feb. 16, 2023, 10:37 p.m.

Related to rp.listbox in rpanel...