rp.menu {rpanel} | R Documentation |
Top level menu for a panel
Description
This function adds a menu to the top of the panel window. When a menu item is selected, a variable is set and an action function is called.
Usage
rp.menu(panel, variable, labels, initval=NULL, action=I,
foreground=NULL, background=NULL, font=NULL,
name=paste("menu", .nc(), sep=""))
Arguments
panel |
the panel to which the menu should be attached should appear. |
variable |
the name of the variable whose value is set by the menu. (Renamed in 2.0 to |
labels |
the labels for the menu options. These values are returned through var. The menu is defined by a list of lists of character strings. Each major menu heading should be the first item in the sub-lists with the submenu items listed afterwards in the same list. Please see the example. |
initval |
the initial value of |
action |
the function which is called when a menu item is chosen. |
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" |
name |
the name of the widget - this is used by |
Details
The function action
should take one argument, which should be the panel to which the listbox is attached.
The list for a menu consisting of "File" and "Edit" only would be defined as
list(list("File"), list("Edit"))
.
The list for a menu consisting of "File" with subitem "Quit", and "Edit" with subitems "Copy", "Cut" and "Paste", would be defined as
list(list("File", "Quit"), list("Edit", "Copy", "Cut", "Paste"))
.
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.
The action function must be defined before the rp.menu
statement as it relies on the function already existing.
Note
The former argument parent
has been discontinued in version 1.1.
References
rpanel: Simple interactive controls for R functions using the tcltk package. Journal of Statistical Software, 17, issue 9.
See Also
Examples
## Not run:
a <- rp.control()
# The action function has to come first so that it already exists for rp.menu,
# as it creates the callback functions on the fly it requires action to already
# be defined.
domenu <- function(panel) {
rp.messagebox(panel$menuchoice, title = "You chose")
panel
}
rp.menu(a, menuchoice, labels=list(list("File","Quit"),
list("Edit","Copy","Cut","Paste")), action=domenu)
## End(Not run)