Domanda

I've developed an interface that allows a user to load and manipulate data. The GUI is developed in Java and all the computational stuff is done in the background by R, linking the two with jri. The idea is that the user doesn't have to have any knowledge of R to use it, it's all options and buttons. However, i'd like to give the user the option to write some code if necessary. So here is my problem:

If I use the following code to start the Rengine and not let the user interact via console, everything works fine:

    Rengine re=new Rengine(null, false, new TextConsole());

But if I use this:

    Rengine re=new Rengine(null, true, new TextConsole());

The functionality of the gui doesnt work. I tried using the

re.startMainLoop();

function after the data was loaded. I was able to manipulate the data from the comand line in R, for example I could make a new variable from a column of the data loaded:

newVariable<-data$column1

But yet again, I couldn't use the gui anymore. Has anyone got any ideas or explainations as to why this is?

Thanks in advance,

Aran

È stato utile?

Soluzione

Fundamentally, if REPL is not running, R is simply used via eval calls from your code. You have control at all times, except during the actual evaluation. That is the most common use, because you can do pretty much anything that way.

The moment you enable the event loop (REPL), you have to implement the callback methods that are used by the loop. By design R surrenders the control only by calling the rReadConsole callback which you have to implement. The example TextConsole works only as a demo, it uses blocking call (readLine()) to wait so you definitely don't want to use that in your GUI. You'll have to implement all callbacks correspondingly to react to your GUI's elements (wait in ReadConsole for your GUI to wake it up from a separate thread, dispatch WriteConsole to your elements etc.). You can have a look at JGR how it's done properly. Unless you are really building a general purpose R GUI, I wouldn't go into that trouble ...

(PS: please use stats-rosuda-devel mailing list for rJava/JRI questions - you get answers much faster)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top