how to make reactive combobox in r using gWidgets2RGtk2

别等时光非礼了梦想. 提交于 2019-12-25 03:42:45

问题


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


回答1:


You should put a handler on the deptnames combobox to update the items combobox. You can mutate the items to select from with items[] <- ... and specify the selected one with svalue(items, index=true) <- .... These would be based on the currently selected value of deptnames which is available through svalue(deptnames). Hope that helps...



来源:https://stackoverflow.com/questions/30204086/how-to-make-reactive-combobox-in-r-using-gwidgets2rgtk2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!