This function adds one or more boxes which allow text to be entered.
rp.textentry(panel, variable, action = I, labels = NULL, names = labels,
title = NULL, initval = rep(NA, length(labels)), pos = NULL,
foreground = NULL, background = NULL, font = NULL, width = 20, keydown = FALSE,
parentname = deparse(substitute(panel)), name = paste("textentry", .nc(), sep=""), ...)
If the argument panel
is set to 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.
the panel in which the text entry box(es) should appear. This may be passed as a panelname string or the panel object itself.
the name of the variable which will be assigned the text entered into the box(es).
the function which is called when the text has been entered.
a character string of labels for the text entry boxes.
a character string of the names of the elements of variable
which can be referred to within action functions.
title above multiple textentries
the initial value(s) for var (optional). The initial value(s)
can also be specified in the call to rp.control
.
the layout instructions. Please see the rp.pos
example and help for full details.
colour of the text
colour of the text background
font to be used
character width of the textboxes
if TRUE the action function will be called on every key press - this may not be wise
this specifies the widget inside which the text entry widget should appear. In the current version, it should not normally be used.
name assigned to the textentries; used for disposal etc
...
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.
The function action
should take one argument, which should be the panel to which the text entry box is attached.
See rp.grid
for details of the grid layout system.
rpanel: Simple interactive controls for R functions using the tcltk package. Journal of Statistical Software, 17, issue 9.
rp.control
if (FALSE) {
plotf <- function(panel) {
with(panel, {
pars <- as.numeric(pars)
xgrid <- seq(0.1, max(c(pars[3], 5), na.rm = TRUE), length = 50)
dgrid <- df(xgrid, pars[1], pars[2])
plot(xgrid, dgrid, type = "l", col = "blue", lwd = 3)
if (!is.na(pars[3])) {
lines(rep(pars[3], 2), c(0, 0.95 * max(dgrid)), lty = 2, col = "red")
text(pars[3], max(dgrid), as.character(pars[3]), col = "red")
}
})
panel
}
panel <- rp.control(pars = c(5, 10, NA))
rp.textentry(panel, pars, plotf, labels = c("df1", "df2", "observed"),
initval = c(10, 5, 3))
rp.do(panel, plotf)
}
Run the code above in your browser using DataLab