gWidgetsWWW LocalServerStart()到JRI

时间:2012-11-09 09:12:36

标签: r jri

我正在尝试使用gWidgetsWWW在网络上展示交互式R图形。当使用我的标准R命令行时,这一切都完美无缺。我使用的代码是例如:

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

但是,我想从Java调用此代码。要做到这一点,我已经设置了JRI,这似乎工作正常。我可以运行我迄今为止尝试的任何R代码,除此之外。

我使用的代码是:

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();     
}

此代码将在我预期的默认浏览器中打开一个新选项卡。但是,此选项卡会保持连接状态,并且不会显示我想要的网页。当我终止Java脚本时,浏览器页面将更新无法建立连接。

我的Java控制台中提供的输出是:

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]

0 个答案:

没有答案