How to Run R on a Server Without X11, and Avoid Broken Dependencies

How to run R on a server without X11, and avoid broken dependencies

Use the virtual framebuffer X11 server -- we do the same to build packages requiring X11 for R builds in headless chroots. Taking e.g. pars of the Build-Depends from rggobi:

xvfb xauth xfonts-base

After installing these you can use the xvfb-run command. If you start R via e.g.

xvfb-run R --no-save

you should now be able to use routines and commands requiring X11 as e.g. some of the plotting devices, or the tcl/tk initialization which also insists on having X11.

The same trick is useful for web servers.

How to run R scripts on servers without X11

I answered this once before -- can cannot make a program which expects X11 to certainly forget about it, but you can use the virtual framebuffer to 'pretend' X11 is present.

So see this older SO question for details and an example.

Compile R with Cairo support without X11

In the most narrow sense, Cairo appears to require x11 headers.

In a wider sense, look into the various answers detailing use of the xvfb virtual x11 server -- they allow you headless use.

Also, you could try building without x11, png, cairo -- and then use one of the two cairo packages from CRAN to create graphs. In Debian/Ubuntu we also have at least the cairoDevice package pre-build for you.

generate png with R

Found the answer to my own question thanks to comments from @Spacedman

Turned out I still needed to install the 'libpango1.0-dev' package. "capabilities('X11');" still gives FALSE but "png();" no longer gives errors, so my problem is fixed. Thank you for pointing me in the right direction!

Alias function name in .Rprofile so that it is used by all R Scripts

Add a message statement so when R starts we can verify that the .Rprofile did, in fact, run. Also use library instead of require because library will give an error right at that point if it fails making it easier to debug. Then instead of putting png in the global environment insert it into the grDevices namespace. To do that it must be unlocked first.

# This code goes in .Rprofile file
message("Hello")
library("Cairo")
unlockBinding("png", asNamespace("grDevices"))
utils::assignInNamespace("png", CairoPNG, "grDevices")

For a different approach check out:

How to run R on a server without X11, and avoid broken dependencies

How to run R on a server without X11, and avoid broken dependencies

Use the virtual framebuffer X11 server -- we do the same to build packages requiring X11 for R builds in headless chroots. Taking e.g. pars of the Build-Depends from rggobi:

xvfb xauth xfonts-base

After installing these you can use the xvfb-run command. If you start R via e.g.

xvfb-run R --no-save

you should now be able to use routines and commands requiring X11 as e.g. some of the plotting devices, or the tcl/tk initialization which also insists on having X11.

The same trick is useful for web servers.



Related Topics



Leave a reply



Submit