Jain
Jain

Reputation: 1009

How to wait for user to input values in combo box in gWidgets2RGtk2?

I want an user input and then source a file based on that input . The R code executes without letting user to select anything and just executes the next statement.

library(gWidgets2RGtk2)

w <- gwindow(title="Hello World",visible=TRUE)
g = ggroup(horizontal = FALSE, cont=w)
glabel("Please select your favorite subject", cont=g)
modeltype <- c("","Science","Math")
op1 <- gcombobox(modeltype, cont=g)

if (svalue(op1)=="Math"){
    source("Rscript1")
}else if (svalue(op1)=="Science"){
    source("Rscript2")
}else{
    source("Rscript3")
}

Now before I close the window or even select the option from my drop down list, it automatically takes "" as the value and goes to the else statement and runs the RScript3 . How can I pause the execution till I get the input from the user. Thanks.

Upvotes: 0

Views: 299

Answers (1)

HubertL
HubertL

Reputation: 19544

The handler function is called when an item is selected in the combo box. It is the place to put your actions:

addHandlerChanged(op1, handler=function(...){
    if (svalue(op1)=="Math"){
      source("Rscript1")
    }else if (svalue(op1)=="Science"){
      source("Rscript2")
    }else{
      source("Rscript3")
    }
})

Upvotes: 1

Related Questions