Re: [R] running R from PHP

2004-02-04 Thread Christian Schulz
Perhaps this is a interesting starting point for you?

http://steve.stat.tku.edu.tw/R_PHP/doR.html

regards,christian


Am Dienstag, 3. Februar 2004 03:26 schrieb [EMAIL PROTECTED]:
 I would like to construct a PHP script that runs R to generate a
 graphics file.  Running R itself is no problem.  However, it seems
 impossible to instantiate one of the graphics devices to create
 output.  For example, the normal bitmap devices (e.g., jpeg, png,
 etc.) are derived from X11, which requires a display.  This seems
 true, even if no output is ever directed to a real display.  For some
 reason, the postscript device seems to suffer from similar problems.

 Is there a trick to creating a graphics device in the absence of an
 actual display in order to create an image in a file?

 Thanks for your help.

 Cheers,
 Brook

 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
 http://www.R-project.org/posting-guide.html

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] running R from PHP

2004-02-04 Thread Peter Dalgaard
[EMAIL PROTECTED] writes:

 Below are 2 scripts (png.R and pdf.R) I am trying to run in R from
 PHP.  
 
  # png.R
  x11(display=:5)
  png(filename=g.png)
  plot(1:5)
  graphics.off()
 
  # pdf.R
  pdf(file=g.pdf)
  plot(1:5)
  graphics.off()
 
 Both run from terminals and png.R will run without a normal X server
 if Xvfb is running.  Neither runs under PHP, though (when invoked as
 R --no-save  xxx.R).  They yield the following errors (with the R
 startup banner deleted for compactness):
 
   x11(display=:5)
   png(filename=g.png)
  Error in X11(paste(png::, filename, sep = ), width, height, pointsize,  : 
unable to start device PNG
  In addition: Warning message: 
  could not open PNG file `g.png'
  Execution halted
 
 and
 
   pdf(file=/usr/pkg/share/httpd/htdocs/test-R/g.pdf)
  Error in PDF(file, old$family, old$encoding, old$bg, old$fg, width, height,  :
unable to start device pdf
  In addition: Warning message:
  cannot open `pdf' file argument `/usr/pkg/share/httpd/htdocs/test-R/g.pdf'
  Execution halted
 
 For reference, the R banner information includes the following:
 
 R : Copyright 2003, The R Development Core Team
 Version 1.6.2  (2003-01-10)
 
 Any help on how to get these scripts to work is greatly appreciated.

Your R version is about a year out of date, but that's hardly the
issue. I don't do PHP, but the error message in both cases has to do
with file opening, so how about checking permissions on your current
directory: Try sticking this into your script
 
   system(id; pwd; ls -la) 

Also notice that web applications often take special security measures
and may change one or all of the following: working directory, root
directory, user id, and group id.

-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] running R from PHP

2004-02-04 Thread Joe Conway
[EMAIL PROTECTED] wrote:
Both run from terminals and png.R will run without a normal X server 
if Xvfb is running.

Neither runs under PHP, though (when invoked as R --no-save  
xxx.R).

They yield the following errors (with the R startup banner deleted 
for compactness):

could not open PNG file `g.png'

cannot open `pdf' file argument
`/usr/pkg/share/httpd/htdocs/test-R/g.pdf'
From the evidence above, I'd guess a file permission error. The web 
server probably runs as the user apache or something similar -- does 
that user have write permission to the place where you are trying to 
create the images?

Try writing to /tmp/g.png and /tmp/g.pdf and see if the files get 
created.

HTH,

Joe

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] running R from PHP

2004-02-03 Thread Prof Brian Ripley
On Tue, 3 Feb 2004, Philippe Glaziou wrote:

 @biology.nmsu.edu [EMAIL PROTECTED] wrote:
  I would like to construct a PHP script that runs R to generate a
  graphics file.  Running R itself is no problem.  However, it seems
  impossible to instantiate one of the graphics devices to create
  output.  For example, the normal bitmap devices (e.g., jpeg, png,
  etc.) are derived from X11, which requires a display.  This seems
  true, even if no output is ever directed to a real display.  

It _is_ documented on the help page, and output _is_ directed to a real 
display: you just mever see it.  It is possible make use a virtual display 
such as that provided by Xvfb.

  For some reason, the postscript device seems to suffer from similar
  problems.
  
  Is there a trick to creating a graphics device in the absence of an
  actual display in order to create an image in a file?
 
 
 If you need a bitmap graphic file, I would suggest the use of
 ImageMagick:

You may as well use the bitmap() device built into R, which is also a 
wrapper for the use of ghostscript.  That too is described on the help 
page.

I have never seen a reported problem with getting postscript output from a
script. After reading the posting guide, please give us some useful
details of what happened.

 cunegonde:~/tmp ls
 foo
 
 cunegonde:~/tmp cat foo
 pdf(file=g.pdf)
 plot(1:5)
 dev.off()
 
 cunegonde:~/tmp R --no-save foo/dev/null  convert g.pdf g.png
 
 cunegonde:~/tmp ls -g
 -rw---1 glaziou  3374 2004-02-03 11:58 g.pdf
 -rw---1 glaziou  4115 2004-02-03 11:58 g.png
 -rw---1 glaziou80 2004-02-03 11:58 foo
 
 
 This works from a unix console without X running (the postcript
 device works similarly on my machine). R can easily be fed this
 way with a file and parameters passed from a php script.
 
 

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] running R from PHP

2004-02-03 Thread Joe Conway
[EMAIL PROTECTED] wrote:
Is there a trick to creating a graphics device in the absence of an
actual display in order to create an image in a file?
Look for Xvfb (X virtual frame buffer). Not sure what OS you are 
running, but on RH9 and Fedora, at least, there is a package called 
XFree86-Xvfb.

I use Xvfb with the following command:

  /usr/X11R6/bin/Xvfb :5 -screen 0 1024x768x16

More specifically I wrote an init script and set Xvfb up to start as a 
service on boot.

Then in R I use:
  x11(display=:5)
HTH,

Joe

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] running R from PHP

2004-02-02 Thread Philippe Glaziou
@biology.nmsu.edu [EMAIL PROTECTED] wrote:
 I would like to construct a PHP script that runs R to generate a
 graphics file.  Running R itself is no problem.  However, it seems
 impossible to instantiate one of the graphics devices to create
 output.  For example, the normal bitmap devices (e.g., jpeg, png,
 etc.) are derived from X11, which requires a display.  This seems
 true, even if no output is ever directed to a real display.  For some
 reason, the postscript device seems to suffer from similar problems.
 
 Is there a trick to creating a graphics device in the absence of an
 actual display in order to create an image in a file?


If you need a bitmap graphic file, I would suggest the use of
ImageMagick:


cunegonde:~/tmp ls
foo

cunegonde:~/tmp cat foo
pdf(file=g.pdf)
plot(1:5)
dev.off()

cunegonde:~/tmp R --no-save foo/dev/null  convert g.pdf g.png

cunegonde:~/tmp ls -g
-rw---1 glaziou  3374 2004-02-03 11:58 g.pdf
-rw---1 glaziou  4115 2004-02-03 11:58 g.png
-rw---1 glaziou80 2004-02-03 11:58 foo


This works from a unix console without X running (the postcript
device works similarly on my machine). R can easily be fed this
way with a file and parameters passed from a php script.

-- 
Philippe Glaziou, MD
Epidemiologist
Institut Pasteur du Cambodge

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html