[R] running R from PHP
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Feb 3 08:04:58 CET 2004
On Tue, 3 Feb 2004, Philippe Glaziou wrote:
> @biology.nmsu.edu <brook at biology.nmsu.edu> 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 glaziou 80 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, ripley at stats.ox.ac.uk
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, UK Fax: +44 1865 272595
More information about the R-help
mailing list