Question: Making PNG figures from plots in R from toolshed (without X11)
0
gravatar for y.hoogstrate
4.2 years ago by
y.hoogstrate460
Netherlands
y.hoogstrate460 wrote:

Hi everyone,

I'm encountering problems when I want to export a plot from R into a PNG, using several R packages from the toolshed(s).
This problem is probably related to the following issue: http://dev.list.galaxyproject.org/package-r-xx-problem-X11-is-not-available-td4663344.html
Therefore, I'm using the package: http://testtoolshed.g2.bx.psu.edu/view/iuc/package_r_3_0_2

When I run R code of the following structure:

png(output_PValue_distribution_plot)
plot(x_var,y_var)
dev.off()

R crashes with the following error: 

Error in .External2(C_X11, paste("png::", filename, sep = ""), g$width,  : 
  unable to start device PNG
Calls: png
In addition: Warning message:
In png(output_PValue_distribution_plot) :
  unable to open connection to X11 display ''
Execution halted

How I interpret this is that in order to produce PNG's, R needs to be compiled with the X11 library.
Because the installer from the toolshed uses the compilation argument " --without-x", it doesn't compile with X11 and so it is not possible to produce PNGs, correct?

I also tried another solution; installation of R with X from the following repository: https://testtoolshed.g2.bx.psu.edu/repository?repository_id=5f7d83aa4f577607 . However, the repository requires several other dependencies which are not programmed within the installer: libx11-dev libxt-dev (and some more, because after all it still work out).

So, what would be the best way to create a PNG figure from my plot(s) within an R instance from a toolshed?
Does it require R to be compiled with X11 or are there ways to overcome this (I am not sure but I thought I read something about Cairo)?

Or would somebody recommend to use a non-R program to convert from e.g. PDF/SVG to PNG? I think this is awckward since R should be the perfect tool to produce PNG figures.

Thanks in advance,

Youri

png x11 package R • 6.2k views
ADD COMMENTlink modified 3.7 years ago • written 4.2 years ago by y.hoogstrate460

Hi Fubar,

Thanks for the fast response. On a ubuntu server (12.04.04 LTS) I get the following error:

/home/galaxy/galaxy/galaxy-dist/toolsheddependencies/R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib/R/bin/exec/R: error while loading shared libraries: libgfortran.so.1: cannot open shared object file: No such file or directory

On my 14.04.01 LTS Desktop instance I get another error related to the missing libgfortran.so.1:

TCL_LIBRARY=../R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib/libtcl8.4.so; export TCL_LIBRARY
TK_LIBRARY=../R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib/libtk8.4.so; export TK_LIBRARY
R_DOC_DIR=../R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib/R/doc; export R_DOC_DIR
R_HOME_DIR=../R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib/R; export R_HOME_DIR
R_INCLUDE_DIR=../R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib/R/include; export R_INCLUDE_DIR
R_SHARE_DIR=../R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib/R/share; export R_SHARE_DIR
R_ROOT_DIR=../R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14; export R_ROOT_DIR
R_HOME=../R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib/R; export R_HOME
RHOME=../R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib/R; export RHOME
R_LIBS=../R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib/R/library; export R_LIBS
PATH=../R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/bin:$PATH; export PATH

$ which R
/home/youri/galaxy/tool-dependencies/R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/bin/R
$ R
/home/youri/galaxy/tool-dependencies/R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib/R/bin/exec/R: error while loading shared libraries: libgfortran.so.1: cannot open shared object file: No such file or directory

 

This file "libgfortran.so.1" is located in "/home/youri/galaxy/tool-dependencies/R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib"

 

ADD REPLYlink modified 4.2 years ago • written 4.2 years ago by y.hoogstrate460

Ah. Thanks for the update.

ok - that particular package is supplied with all the dependencies compiled in - so there's something odd going on. 

Are you reporting failures from your own Galaxy R/graphics tool which specifies that R310 package as a dependency? 

If you are trying to test that package R binary outside the Galaxy tool dependency environment then the various env.sh files which are sourced to set up the paths (including to gfortran libs) will be missing and it won't work.

Maybe we need to know a little more about how you are trying to use/test it - if it installed without error, then any local tools which depend on it will load the right env.sh and it should work!

 

ADD REPLYlink modified 4.2 years ago • written 4.2 years ago by fubar1.1k

I did it both ways and got the same error:

 - via linking the repository of R310 and running an analysis

- by just running the "env.sh" script in terminal (as shown in the previeous post) and subsequently calling R

Both have problems with linking the gfortran link library. If I find some time I will double check whether I made some errors, but I doubt it because I've been playing with it for quite some time. Also adding the directory where the file is located "/home/youri/galaxy/tool-dependencies/R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14/lib" to the env variables, did not solve the issue.

The installation finished correctly, but the R binary can not find the files (both from commandline as from Galaxy)

ADD REPLYlink modified 4.2 years ago • written 4.2 years ago by y.hoogstrate460
2

Youri,

I was able to reproduce this error, and determined that the tarball referenced by the tool dependency definition was missing a symbolic link to the gfortran library in the right place for $INSTALL_DIR/lib/R/bin/exec/R to find it. I have created that link and repackaged the tarball. If you go to the installed repository and select the "manage tool dependencies" option, then uninstall and reinstall the R tool dependency, R should run correctly.

ADD REPLYlink written 4.2 years ago by Dave B.410

Hi Dave,

Thanks for the fix. The installer issue is indeed fixed. Yet, I still get the X11 error:

/galaxy/tool-dependencies/R/3.1.0/iuc/package_r_3_1_0/a6cc7706ea14$ ./bin/R

R version 3.1.0 (2014-04-10) -- "Spring Dance"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> png("/tmp/a.png")
Error in png("/tmp/a.png") : X11 is not available

I want to recall that also this installer is compiled with the "--without-x" flag, which I expect to be the cause of the problem. If desired, I can test it on multiple machines and I can also test it running from a Galaxy tool although this behavior should not change.

As I mentioned earlier, I partially managed to solve this issue by using the https://testtoolshed.g2.bx.psu.edu/view/joachim-jacob/package_r3_withx repository that is compiled with X11. I say partially because unfortnuately compilation failed on several instances.

/galaxy/tool-dependencies/package_r3_withx/3.0.1/joachim-jacob/package_r3_withx/abc274f22004$ ./bin/R

R version 3.0.1 (2013-05-16) -- "Good Sport"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> png("/tmp/a.png")
> plot(c(1,0),c(1,0))
> dev.off()
null device 
          1 

As workaround/temporary solution I now create PDF files and I convert it after R with graphicsmagick:

https://testtoolshed.g2.bx.psu.edu/view/iuc/package_graphicsmagick_1_3

Conversion can be achieved using the commands in the <command></command> tag of the wrappers XML file:

#set $png_file = str($pdf_file) + ".png"
gm convert $pdf_file $png_file ;
ADD REPLYlink modified 4.2 years ago • written 4.2 years ago by y.hoogstrate460
1
gravatar for y.hoogstrate
3.7 years ago by
y.hoogstrate460
Netherlands
y.hoogstrate460 wrote:

I found a very simple workaround at the following website: https://github.com/virtualstaticvoid/heroku-buildpack-r/issues/13

You could replace any:

png(filename)

with:

bitmap(filename,"png16m")

In your R script(s). I hope this helps

ADD COMMENTlink modified 2.1 years ago • written 3.7 years ago by y.hoogstrate460
1
gravatar for fubar
4.2 years ago by
fubar1.1k
Australia
fubar1.1k wrote:

Hi, would you please try the later IUC R at https://testtoolshed.g2.bx.psu.edu/view/iuc/package_r_3_1_0 which has cairo and other dependencies too and let us know how you go - it *should* work...and if not, any error messages will help us get the problem sorted out - thanks.

ADD COMMENTlink modified 4.2 years ago • written 4.2 years ago by fubar1.1k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 182 users visited in the last hour