10

I'm running R-shiny (R version 3.0.1 (2013-05-16)) on a VM (Red Hat Enterprise Linux Server release 6.4). Everything works, i.e., server starts up, and application runs etc... as long as I don't try to plot a graph

renderPlot

I then see on the main panel a message [error : unable to start device png]. I would post my whole code but this problem I think has to do with rendering plots as when I use renderText and spit out some data it works just fine.

Actually when I just type in png() in R I get this error [ Error in .External2(C_X11, paste("png::", filename, sep = ""), g$width, : unable to start device PNG In addition: Warning message: In png() : unable to open connection to X11 display '' ] of course if I forward via ssh -X to my mac, I can type in png() no problem and plot data etc...

-A few more things to note, when I type in capabilties() I find the only things that are false are jpeg, tiff, X11, aqua, and profmem (so png and cairo are True)

-I've installed libpng, cairo, and libX11, libX11-devel, libXt, libXt-devel before building R from source

I'm guessing my problem is that I need to have X server running. In addition the DISPLAY variable is null.

So, I guess when it boils down to it my question is ... assuming my logic is correct.

1) Do I need to run / start X server [ currently it terminates after starting for some reason] or can I just set the DISPLAY variable?

2) If I can just set my DISPLAY variable what should I set it to (localhost:0.0 hasn't worked)

Obviously if there is something I'm missing these questions may be irrelevant.

Thanks in advance and sorry for rambling, wanted to be thorough.

PJ

user2510097
  • 101
  • 1
  • 1
  • 3

2 Answers2

15

Does it help if you set option(bitmapType = 'cairo')? I have been skeptical about how R chooses the bitmap device type using .Call(C_cairoProps, 2L) in grDevices:::.onLoad() (this might be a bug, but I cannot say it for sure).

The option bitmapType falls back to Xlib if the test of cairo fails, thus giving you a cryptic error message about X11. Note the type argument in png():

> args(png)
function (filename = "Rplot%03d.png", width = 480, height = 480, 
    units = "px", pointsize = 12, bg = "white", res = NA, ..., 
    type = c("cairo", "cairo-png", "Xlib", "quartz"), antialias) 

The default value of this argument is getOption('bitmapType'), and in your case it is Xlib due to the test in grDevices:::.onLoad(). If you are 100% sure that cairo works, you can change this option, say, in your ~/.Rprofile.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • 1
    Hello Yihui. Do you suggest to set `option(bitmapType='cairo')` in the `server.R` file ? – Stéphane Laurent Jul 30 '13 at 19:04
  • @StéphaneLaurent yes, that is also one way to go; I mentioned `~/.Rprofile` above, which means to set this option globally for all your R sessions – Yihui Xie Jul 30 '13 at 19:06
  • I have tried `options(bitmapType='cairo')` in the `server.R` file but that does not change anything. – Stéphane Laurent Aug 01 '13 at 10:25
  • @StéphaneLaurent you mean exactly the same error message? can you simply test `png(tempfile(), type='cairo'); dev.off()`? – Yihui Xie Aug 01 '13 at 18:44
  • Yes exactly the same error message. Do you mean typing this line as a command line ? (I'll try tomorrow, I'm at home now) – Stéphane Laurent Aug 01 '13 at 18:52
  • @StéphaneLaurent Yes, type the code as a command line in an R terminal. The same error message indicates the option was not respected, so I ask you to hardcode the option and see if it works. – Yihui Xie Aug 01 '13 at 19:24
  • 4
    Yihu, my colleague (Linux server admin) has recompiled R-3.0.1 with cairo, and now everything works well with `options(bitmapType='cairo')` ! Thank you ! – Stéphane Laurent Aug 02 '13 at 09:47
  • 1
    I had to add `options(bitmapType='cairo')` to my `~/.Rprofile` – Shaun Jackman Jul 07 '17 at 00:59
2

I was able to resolve this by installing a few additional development packages and then uninstalling/reinstalling R from source. All the other recommended options did not work for me until this.

sudo yum install pango-devel pango libpng-devel

Go to directory where source R file was installed:

make uninstall
./configure --with-readline=no (or ./configure might work for you)
make
make install
josliber
  • 43,891
  • 12
  • 98
  • 133
Brian Correro
  • 143
  • 1
  • 1
  • 8