2

I'm trying to present interactive R graphics on the web using gWidgetsWWW. When using my standard R command line this all works perfectly. The code I use is for example:

> library(gWidgetsWWW) 
> localServerOpen('Examples/ex-simple-gui.R', package='gWidgetsWWW')

However, I would like to call this code from Java. To do this I've set up JRI and this seems to work fine. I can run any R code I've tried so far except for this.

The code I use is:

public static void main(String[] args) {
    // just making sure we have the right version of everything
    if (!Rengine.versionCheck()) {
        System.err.println("** Version mismatch - Java files don't match library version.");
        System.exit(1);
    }
    System.out.println("Creating Rengine (with arguments)");

    Rengine re=new Rengine(args, false, new TextConsole());
    Rengine.DEBUG = 1000;
    System.out.println("Rengine created, waiting for R");

    if (!re.waitForR()) {
        System.out.println("Cannot load R");
        return;
    }

    re.eval("library(gWidgetsWWW)");
    re.eval("localServerOpen('Examples/ex-simple-gui.R', package='gWidgetsWWW')");

    re.startMainLoop();     
}

This code will open a new tab in my default browser as I expect it to do. However, this tab keeps connecting and will not display the web page I want it to. When I terminate the Java script the browser page will update that a connection could not be made.

The output provided in my Java console is:

Rengine created, waiting for R
Rengine.eval(library(gWidgetsWWW)): BEGIN Thread[main,5,main]
Loading required package: proto
Loading required package: filehash
filehash: Simple key-value database (2.2-1 2012-03-12)
Loading required package: digest
Loading required package: rjson
Rengine.eval(library(gWidgetsWWW)): END (OK)Thread[main,5,main]
Rengine.eval(localServerOpen('Examples/ex-simple-gui.R', package='gWidgetsWWW')):         BEGIN Thread[main,5,main]
starting httpd help server ... done
Rengine.eval(localServerOpen('Examples/ex-simple-gui.R', package='gWidgetsWWW')): END (OK)Thread[main,5,main]
Matthijs Brouns
  • 2,299
  • 1
  • 27
  • 37

0 Answers0