[R] How do I define the method for gcheckboxgroup in gWidgets?

Bryan Hanson hanson at depauw.edu
Thu Jun 25 17:29:14 CEST 2009


Hi All...

I¹m trying to build a small demo using gWidgets which permits interactive
scaling and selection among different things to plot.  I can get the widgets
for scaling to work just fine.  I am using gcheckboxgroup to make the
(possibly multiple) selections.  However, I can¹t seem to figure out how to
properly define the gcheckboxgroup; I can draw the widget properly, I think
my handler would use the svalue right if it actually received it.  Part of
the problem is using the index of the possible values rather than the values
themselves, but I'm pretty sure this is not all of the problem.  I've been
unable to find an example like this in any of the various resources I've
come across.

BTW,  report.which is really only there for troubleshooting.  It works to
return the values, I can't get it to return the indices, which are probably
what I need in this case.

A demo script is at the bottom and the error is just below.

> tmp <- gcheckboxgroup(stuff, handler = report.which, index = TRUE,
+     checked = c(TRUE, FALSE, FALSE, FALSE, FALSE), container = leftPanel)
> add(tmp, value = 1, expand = TRUE)
Error in function (classes, fdef, mtable)  :
  unable to find an inherited method for function ".add", for signature
"gCheckboxgroupRGtk", "guiWidgetsToolkitRGtk2", "numeric"

This error suggests that I don't have a method - I agree, but I don't know
what goes into the method for gcheckboxgroup.

For the sliders, it's clear to me how the actions and drawing of the widgets
differ, but not so for gcheckboxgroup.

A big TIA, Bryan
*************
Bryan Hanson
Professor of Chemistry & Biochemistry
DePauw University, Greencastle IN USA

Full Script:

x <- 1:10
y1 <- x
y2 <- x^2
y3 <- x^0.5
y4 <- y^3
df <- as.data.frame(cbind(x, y1, y2, y3, y4))
stuff <- c("y = x", "y = x^2", "y = x^0.5", "y = x^3")
which.y <- 2 # inital value, to be changed later by the widget

# Define a function for the widget handlers

update.Plot <- function(h,...) {
    plot(df[,1], df[,svalue(which.y)], type = "l",
    ylim = c(0, svalue(yrange)), main = "Interactive Selection & Scaling",
    xlab = "x values", ylab = "y values")
    } 

report.which <- function(h, ...) { print(svalue(h$obj), index = TRUE) }

# Define the actions & type of widget, along with returned values.
# Must be done before packing widgets.

yrange <- gslider(from = 0, to = max(y), by = 1.0,
    value = max(y), handler = update.Plot)
which.y <- gcheckboxgroup(stuff, handler = report.which, index = TRUE,
    checked = c(TRUE, FALSE, FALSE, FALSE, FALSE))

# Assemble the graphics window & groups of containers

mainWin <- gwindow("Interactive Plotting")
bigGroup <- ggroup(cont = mainWin)
leftPanel <- ggroup(horizontal = FALSE, container = bigGroup)

# Format and pack the widgets, & link to their actions/type

tmp <- gframe("y range", container = leftPanel)
add(tmp, yrange, expand = TRUE)
tmp <- gcheckboxgroup(stuff, handler = report.which, index = TRUE,
    checked = c(TRUE, FALSE, FALSE, FALSE, FALSE), container = leftPanel)
add(tmp, value = 1, expand = TRUE)


# Put it all together

add(mainWin, ggraphics()) # puts the active graphic window w/i mainWin




More information about the R-help mailing list