[R] R GUI programming

Hao Liu hao.liu at bms.com
Fri Feb 16 21:52:47 CET 2007


Hi, All:

I am having a problem with handling global variable value in GUI 
programming, I hope R gurus can give me some advice on it.

What I want to do is to read in a dataset, display some information 
based on the input and do some calculation on the dataset:
However,  I am having trouble organizing my code, as the following code 
goes,  the comboBox section will have to be put
in the loaddataset function, otherwise, since comboBox is displayed upon 
GUI initialization, later changes to the .dataset won't be reflected in 
the display.
--
dataset.header <- tclVar("header information")
 .dataset <- 0

loaddataset <- function(.dataset) {           # this function is bind to 
a tkbutton
         file <- tclvalue(tkgetOpenFile())
          if (!length(file)) return()
          tclvalue(dataset.file)<-file
          .dataset <- read.csv(file,header=TRUE)   # read in .CSV file 
to R object
          cat(colnames(.dataset))
          tclvalue(dataset.header) <- colnames(.dataset)
          cat(paste("after assign: ", tclvalue(dataset.header), sep=""))
          tclvalue(output.dir) <- tclfile.dir(file)
          tkmessageBox(title="Setting Output Directory", 
message=paste("Setting output directory to ", tclvalue(output.dir), 
sep=" "), icon="info",
          type="ok")
          #cat(paste("\"The column names are: ", colnames(dataset), 
"\"\n", sep=""))
          #cat(paste("\n the dimension is: ", dim(.dataset), "\n", sep=""))
      #headers <- paste("\"", colnames(.dataset), "\"", sep="")   
      # parameters derived from input data....
    dataset.label <- tklabel(boxplotcanvas, text="Select variable from 
dataset: ", font=font1)
    comboBox <- 
tkwidget(boxplotcanvas,"ComboBox",editable=FALSE,values=tclvalue(dataset.header))
    tkgrid(dataset.label, comboBox)
    tkgrid.configure(dataset.label, sticky="w")
    tkgrid.configure(comboBox, sticky="e")
}
---
The same situation for if I want to plot the readin dataset, since I 
want to bind the plot function to a tkbutton, I still have not find a 
way to pass the readin .dataset over to the plot
function.

Thanks
Hao



More information about the R-help mailing list