I am running on my Mac the following code which creates a png file in /
tmp. Looks ok but I can't include this in my default/index view. What
is going wrong?
Create a png file in controller:
def index():
from rpy2.robjects.packages import importr
from rpy2 import robjects
from rpy2.robjects import Formula
from rpy2.robjects.vectors import IntVector, FloatVector
from rpy2.robjects.lib import grid
grdevices = importr('grDevices')
grdevices.png(file="/tmp/rweb2output.png" , width=512, height=512)
# Plotting code
rprint = robjects.globalenv.get("print")
stats = importr('stats')
base = importr('base')
lattice= importr('lattice')
xyplot = lattice.xyplot
datasets=importr('datasets')
mtcars = datasets.mtcars
formula = Formula('mpg ~ wt')
formula.getenvironment()['mpg'] = mtcars.rx2('mpg')
formula.getenvironment()['wt'] = mtcars.rx2('wt')
p=lattice.xyplot(formula)
rprint(p)
# close graphical device so file will be closed.
grdevices.dev_off()
view in viewer:
<p> Here is the R output via a tmp png file
<object src="/tmp/rweb2output.png"> obj text </OBJECT>
</p>
I have tried some other options with OBJECT and DATA and IMG.
Regards,
Richard