Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot open file 'Rplots.pdf' using rapache

Tags:

r

rapache

I am trying to generate a pie chart on my browser using rApache

my R code is this

library(MASS)                  
school = painters$School  
school.freq = table(school)
pie(school.freq)

when i run this on browser ... i am getting this error

rApache has something to tell you. View source and read the HTML comments at the end.

Error in function (file = ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf"), : cannot open file 'Rplots.pdf'

any idea why i am getting this error?

like image 483
mark gill Avatar asked May 09 '26 14:05

mark gill


1 Answers

pie() and other plotting commands will try to write to a PDF by default. If you want to display an image in a web page using RApache, then this approach is not what you want. You have to tell RApache what you want it to do.

Look in the test directory which was created when you unpacked the RApache source code. There, you will find several scripts which illustrate how to render a PNG image on the web page. For example in sendBin.R, you will find this code:

setContentType("image/png")
t <- tempfile()
png(t,type="cairo")
plot(rnorm(10))
dev.off()
sendBin(readBin(t,'raw',n=file.info(t)$size))
unlink(t)
DONE

If you replace the line plot(rnorm(10)) with your pie(school.freq), then save this file in the right place (e.g. /var/www/R/plot.R), your chart should appear on the web page.

Make sure you read the RApache documentation and configure it so as R scripts can be run from locations in your web root.

like image 88
neilfws Avatar answered May 11 '26 04:05

neilfws



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!