rp.checkbox: A checkbox control for rpanel

View source: R/checkbox.r

rp.checkboxR Documentation

A checkbox control for rpanel

Description

Adds one or more checkboxes to the panel, to control logical variables.

Usage

rp.checkbox(panel, variable, action=I, labels=NULL, names=NULL, title=NULL, 
  initval=rep(FALSE, length(labels)), pos=NULL, doaction=FALSE, foreground=NULL,
  background=NULL, font=NULL, parentname=deparse(substitute(panel)),
  name=paste("checkbox", .nc(), sep=""), ...) 

Arguments

panel

the panel in which the checkbox(es) should appear.

variable

the name of the variable within the panel that the checkbox(es) should control.

action

the function to call whenever a checkbox is clicked.

labels

the labels of the checkboxes. The length of labels determines the number of checkboxes created. This default value for labels is the name of variable, and therefore a single checkbox.

names

the names attached to the elements of variable. These provide a helpful means of referring to particular items in multiple checkboxes when defining the action function. If names were not specified in the call to rp.control then names is set to labels.

title

the title of the checkbox group. This defaults to the name of the variable variable.

initval

the initial value for variable (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.

doaction

a logical variable which determines whether the action function is called when the widget is created. The default is FALSE, so that the rp.do function should be called after all widgets have been created, to initialise the state of the panel display.

foreground

this sets the colour of text e.g. "navy"

background

this sets the background colour of text e.g. "white"

font

this sets the text font e.g. "Arial"

parentname

this specifies the widget inside which the checkbox(es) should appear.

name

the name of the checkbox.

...

...

Details

The function action should take one argument, which should be the panel to which the checkbox is attached. See rp.grid for details of the grid layout system.

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.

References

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

See Also

rp.radiogroup,rp.control

Examples

## Not run: 
   plot.hist <- function(panel) {
	 with(panel, {
		xlim <- range(c(x, mean(x) + c(-3, 3) * sd(x)))
	   if (panel$cbox[3])
	      clr <- "lightblue" else clr <- NULL
	   hist(x, freq = FALSE, col = clr, xlim = xlim)
	   if (panel$cbox[1]) {
	      xgrid <- seq(xlim[1], xlim[2], length = 50)
	      dgrid <- dnorm(xgrid, mean(x), sd(x))
	      lines(xgrid, dgrid, col = "red", lwd = 3)
	      }
	   if (panel$cbox[2])
	      box()
	   })
	 panel
	 }
   x <- rnorm(50)
   panel <- rp.control(x = x)
   rp.checkbox(panel, cbox, plot.hist, 
      labels = c("normal density", "box", "shading"), title = "Options")
   rp.do(panel, plot.hist)

## End(Not run)

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

Related to rp.checkbox in rpanel...