This function adds a `combobox' to the panel. When an item is pressed, a variable is set and an action function is called.
rp.combo(panel, variable, prompt=NULL, vals, initval=vals[1], pos=NULL, action=I,
foreground=NULL, background=NULL, font=NULL, editable=FALSE,
parentname=deparse(substitute(panel)), name=paste("combo", .nc(), sep=""), ...)
If the parameter 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.
the panel in which the combobox should appear.
the name of the variable whose value is set by the combobox.
the label for the combobox.
the values of variable
used by the combo.
the initial value of variable
(optional). The initial value can also be specified in the call to rp.control
.
the layout instructions. Please see the rp.pos
example and help for full details.
the function which is called when an item is chosen.
colour of the text
colour of the text background
font to be used
whether the combobox can be edited or not.
this specifies the widget inside which the combobox should appear.
name assigned to the combobox, used for disposing of the widget
...
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 combobox is attached.
See rp.grid
for details of the grid layout system.
This function makes use of the BWidget extension to the Tcl/Tk system. If Bwidget has not been installed on your system, download it from https://sourceforge.net/projects/tcllib/files/BWidget/ and expand the compressed file into a folder. On a Windows machine, this folder should then be copied into the folder containing the Tcl libraries that were installed as part of R. This may be in a location such as C:\Program Files\R\R-4.0.2\Tcl\lib (with an obvious change to the version number of R being used). On a Mac, the downloaded folder should be copied into the folder where the main Tcl package is located (note: not inside the Tcl folder but at the same level as the Tcl folder). This may be in a location such as /usr/local/lib.
Note that rp.listbox
provides an alternative to rp.combo
if the latter is unavailable.
rpanel: Simple interactive controls for R functions using the tcltk package. Journal of Statistical Software, 17, issue 9.
rp.checkbox
, rp.control
if (FALSE) {
callback <- function(panel) {
print(panel$option)
panel
}
panel <- rp.control()
rp.combo(panel, option, "Pick an option:",
c("Option1","Option2","Other options"), action=callback)
}
Run the code above in your browser using DataLab