2

I am making a GUI for a R program which does some quite lengthy calculations while constantly updating plots on a gwidgets GUI. I would like to give the user the possibility to interrupt the calculations if they take too long. I am trying to use a stop button.

The problem is that while the function is running, the window is greyed out and none of the controls will respond, so it is not possible to click the stop button.

This problem only occurs when running the program on Ubuntu, I tested the script on Windows and it worked as expected.

Here's a minimal working example of my code illustrating what I am trying to do:

require(gWidgets2RGtk2)
require(gWidgets2)

stopsignal <- FALSE
w <- gwindow()
button_gp <- ggroup(cont=w)
gbutton("calculate", cont=button_gp, handler=function(...) calculate())
gbutton("stop", cont=button_gp, handler=
          function(...) assign("stopsignal", TRUE , envir = .GlobalEnv))

calculate <- function() {
  while(TRUE) { 
    #do something
    print("Hello World")
    if(stopsignal) break
  }
}

I am trying to understand why Ubuntu is behaving differently and how I can fix it.

vrajs5
  • 4,066
  • 1
  • 27
  • 44
drat
  • 121
  • 4

0 Answers0