如何使用gWidgets2RGtk2在r中使反应组合框 [英] how to make reactive combobox in r using gWidgets2RGtk2
问题描述
对于我的GUI,我想有2个组合框。
For my GUI, i want to have 2 combo box.
组合框1显示Departments
combobox 1 to display Departments
combobox 2在combobox1中显示所选部门中的项目
combobox 2 to display items in the selected department from combobox1
因此,如果用户在第一个组合框中选择电子作为部门, productElectronics
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
推荐答案
您应该在 deptnames
组合框中添加处理程序以更新项目
组合框。您可以改变项目以使用 items []< - ...
选择,并使用 svalue指定所选项目(items,index = true )< - ...
。这些将基于通过 svalue(deptnames)
可用的 deptnames
的当前选择的值。希望有助于...
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...
这篇关于如何使用gWidgets2RGtk2在r中使反应组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!