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
@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. 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 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. -- Philippe Glaziou, MD Epidemiologist Institut Pasteur du Cambodge
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
brook at biology.nmsu.edu 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
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 brook at biology.nmsu.edu:> 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 > > ______________________________________________ > R-help at stat.math.ethz.ch 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