Reputation: 1319
Is there anybody who is succesfully working with JRI and rJava? I want to put some graphs, plots made in R into my Java application, but without success. Can anybody provide working example. Here is what I found, but its not working.
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
/**
* @author Nero
*In this file, I will try to plot a simple example, only to test how it?s possible to plot through java
*Attention: Nothing will work if you have not included the JRI.jar as library ( through properties)*/
public class TryPlot {
public static void main(String[] args) {
// TODO Auto-generated method stub
//start the Rengine (JRI)
Rengine re = new Rengine(null, false, null);
//in R: >a<- c(1.2,2.3,4.5) :
double da[] = {1.2, 2.3, 4.5};
long xp3 = re.rniPutDoubleArray(da);
re.rniAssign("a", xp3, 0);
//look up for a:
REXP x;
x = re.eval("a");
System.out.println(x);
//THE PROBLEM: The window opens, but nothing happens???
re.eval(" plot(a)");
}
}
Upvotes: 3
Views: 2391
Reputation: 21
I think the normal R graphics device works only if you use it in the R GUI, not if started from java or the commandline. So I used the package "JavaGD" as a graphics device and this works fine. the Plot is printed in a normal JFrame which can even be extended by subclassing it.
Upvotes: 2