rp.checkbox {rpanel} | R 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 |
names |
the names attached to the elements of |
title |
the title of the checkbox group. This defaults to the name of the variable
|
initval |
the initial value for |
pos |
the layout instructions. Please see the |
doaction |
a logical variable which determines whether the action function is called
when the widget is created. The default is FALSE, so that the |
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
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)