How do you update the contents of R gWidget?

I am creating a GUI in R using gWidgets (more specifically gWidgetstcltk ). I would like to know how to update the content of select type widgets like gdroplist and gtable . I currently have a pretty hacky method of removing a widget and re-creating it. I am sure there is a better way.

This simple example displays all the variables in a global environment.

 library(gWidgets) library(gWidgetstcltk) create.widgets <- function() { grp <- ggroup(container = win) ddl <- gdroplist(ls(envir = globalenv()), container = grp) refresh <- gimage("refresh", dirname = "stock", container = grp, handler = function(h, ...) { if(exists("grp") && !is.null(grp)) { delete(win, grp) } create.widgets() } ) } win <- gwindow() create.widgets() 
+6
r gwidgets
source share
3 answers

AFAIK these update events are often owned by the window manager, so it can be tricky.

+2
source share

I spoke with John Verzani, the creator of gWidgets * packages, and the answer is incredibly simple (although not entirely intuitive). You access the contents of list type widgets using widget_name[] .

 library(gWidgets) library(gWidgetstcltk) get_list_content <- function() ls(envir = globalenv()) # or whatever win <- gwindow() grp <- ggroup(container = win) ddl <- gdroplist(get_list_content(), container = grp) refresh <- gimage("refresh", dirname = "stock", container = grp, handler = function(h, ...) ddl[] <- get_list_content() ) 

Note that there are some limitations: switch lists must remain the same length.

 win <- gwindow() rb <- gradio(1:10, cont = win) rb[] <- 2:11 # OK rb[] <- 1:5 # Throws an error; can't change length. 
+4
source share

While the title of the question is ambiguous, whether they speak of the need for a forced visual update or just a change in the content, I recently had a similar problem updating gstatusbar before and after a long job. Although there is an alternative to REPL called REventLoop , I found that using the tcl timer is quite convenient.

 tcl("after", 300, my_long_operation) 

So, I update gstatusbar before a long operation, and then I set up a timer that will run my function in less than a second, which takes some time, and at the end of this function I update gstatusbar using something like

 svalue(sb) <- "Ready" 
+1
source share

All Articles