For my GUI, i want to have 2 combo box.
combobox 1 to display Departments
combobox 2 to display items in the selected department from combobox1
So if the user selects "Electronics" as department in first combobox, productElectronics should be selected for 2nd comboBox else productArts should be selected.
library(gWidgets2RGtk2)
deptnames <- c("Arts","Electronics")
productArts <- c("Beads","Crayons")
productElectronics <- c("iPad","Apple Watch")
a1 <-c()
w <- gwindow("combobox example")
gp <- ggroup(horizontal = FALSE,container=w)
dept <- gcombobox(deptnames, container = gp )
items <- gcombobox(a1, container = gp ,
handler = function(h,...){
# oldval <- svalue(dept)
if (svalue(dept) == "Arts")
{
a1 <- productArts
}
if(svalue(dept) == "Electronics")
{
a1 <- productElectronics
}
}
)
For the above code nothing populates for any value selected in department combobox
You should put a handler on the
deptnames
combobox to update theitems
combobox. You can mutate the items to select from withitems[] <- ...
and specify the selected one withsvalue(items, index=true) <- ...
. These would be based on the currently selected value ofdeptnames
which is available throughsvalue(deptnames)
. Hope that helps...