I’m new to R world and I’m having some difficulties working with gWidgets and I hope someone out there can help me. First of all my R version is 2.15.2., and I’m using Windows 7 32-Bit.
I want to create a GUI with Input/Output and a selection (Yes, No), so if the user selects (using gradio) “Yes”, will display an extra set of parameters, if “No”, then it should disappear (those parameters), or be gray out. And finally, if the user click OK button, then it will pass some parameters that will be use (later on) to call another function.
Here are my questions:
- Do you have an idea how can I remove the parameters when the user selects “No”, right now, if I click no, it prints what I want, but when I click “Yes” again, it displays another three parameters.
- Do you know how can I pass the arguments when user click “OK”, this is for later when click OK, it will call (or source) another function in a different r code
Many thanks in advance for all your help
Cesar
P.S. Below is my code:
require(gWidgets)
options("guiToolkit"="RGtk2")
#options(expressions=500000)
w <- gwindow("")
g <- ggroup(horizontal = FALSE, container = w)
glabel("Input/Output", container = g)
inputFileDir <- gfilebrowse (text = "Select file...", type = "open", quote = FALSE,
filter = list("Text File" = list(patterns = c("*.txt"))), container = g)
svalue(inputFileDir)
outputFileDir <- gfilebrowse (text = "Input file name...", type = "save", quote = FALSE,
filter = list("Text File" = list(patterns = c("*.txt"))), container = g)
svalue(outputFileDir)
glabel("Direction?", container = g)
DirSelec <- c("Yes","No")
rbF <- function(h,...){
if (svalue(h$obj, index=TRUE) == 1){
print ( "define handler here" )
glabel("Meridional (Raster file):", container = g)
fieldConstrainDir_v <- gedit("", container = g, default = 0)
svalue(fieldConstrainDir_v)
glabel("Zonal (Raster file):", container = g)
fieldConstrainDir_u <- gedit("", container = g, default = 0)
svalue(fieldConstrainDir_u)
glabel("Max. Angle:", container = g)
maxAng <- gedit("", width = 3, initial.msg = "Paste the path to the raster file (no extensions)", default = 0, container = g)
svalue(maxAng)
}else {
#(svalue(h$obj, index=TRUE) == 2)
print ( "When User click NO, it needs to go or gray out" )
}
}
rb <- gradio(DirSelec, container = g)
selected = svalue(rb, index=TRUE) <- 2
rbH <- addHandlerClicked(rb, handler = rbF)
bg <- ggroup(container = g)
addSpring(bg)
onOK <- function(h,...){
print(svalue(inputFileDir))
#chartr("\\", "/", print(svalue(inputFileDir)))
print(svalue(outputFileDir))
print(svalue(fieldConstrainDir_v))
print(svalue(fieldConstrainDir_u))
print(svalue(maxAng))
}
gbutton(" OK ", container = bg, handler = onOK)
gbutton(" Cancel ", container=bg, handler = function(h,...) dispose(w))