Are you especially attached to the idea of ββusing tcltk? I worked on something similar with the gWidgets package and had some success. According to this CRAN site, "gWidgets provides an API that is independent of the tools for building interactive graphical interfaces." This package uses tcltk or GTK2, and I used the GTK2 part. Here is a brief example of a GUI with a spinbat for changing i . I also added a bit of fantasy to your function because you mentioned that you are planning time series, so I made an x ββaxis.
data<-data.frame(rnorm(11),rnorm(11),rnorm(11)) i = 1 fplot <- function(i, data = data){ library(ggplot2) TimeStart <- as.Date('1/1/2012', format = '%m/%d/%Y') plotdat <- data.frame(Value = data[ ,i], Time = seq(TimeStart,TimeStart + nrow(data) - 1, by = 1)) myplot <- ggplot(plotdat, aes(x = Time, y = Value))+ geom_line() print(myplot) } library(gWidgets) options(guiToolkit = 'RGtk2') window <- gwindow ("Time Series Plots", visible = T) notebook <- gnotebook (cont = window) group1 <- ggroup(cont = notebook, label = "Choose i", horizontal=F) ichooser <- gspinbutton(cont = group1, from = 1, to = ncol(data), by = 1, value = i, handler = function(h,...){ i <<- svalue(h$obj)}) plotbutton <- gbutton('Plot', cont = group1, handler=function(h,...){ fplot(i, data)}) graphicspane1 <- ggraphics(cont = group1)
source share