Warning: Error in .External2: unable to start device PNG

This might be discussed before. But, I cannot find the solution for my specific trouble.

I was trying to run a shiny app on EC2, but failed to render plots due to the failure to start a PNG device obviously. My R version is 3.5.1, Ubuntu version is 16.04. The error msg is like:

Warning in pngfun(filename = filename, width = width, height = height, res = res,  :
  unable to open connection to X11 display ''
Warning: Error in .External2: unable to start device PNG
  123: pngfun
  122: startPNG
  121: drawPlot
  107: <reactive:plotObj>
   91: drawReactive
   78: origRenderFunc
   77: output$umi_cell_ranking
    1: runApp

capabilities() result is as below:

       jpeg         png        tiff       tcltk         X11        aqua 
       TRUE        TRUE       FALSE       FALSE        TRUE       FALSE 
   http/ftp     sockets      libxml        fifo      cledit       iconv 
       TRUE        TRUE        TRUE        TRUE        TRUE        TRUE 
        NLS     profmem       cairo         ICU long.double     libcurl 
       TRUE       FALSE       FALSE        TRUE        TRUE        TRUE 

I assume I installed necessary libraries as guided by online trouble shooting, but not sure complete. Anybody met this before and got a solution?

1 Like

This looks like the same thing being reported over here:

I’m afraid troubleshooting hasn’t gotten very far yet, though.

How did you install that R version? I had same issues with wget and config/make from source. If you update your keys and install the r-base 3.4, it worked for me

Hi Vinnyp90, I did the same thing as you, install 3.5.1 from source. Glad to hear downgrade R solve the problem, but the pipeline I am building recommends 3.5 version. I don't have the problem on my local MAC with binary version of R3.5. It might be sth wrong from compiling R 3.5 source. :frowning: Not sure.

Do you mind sharing the commands you are executing to build R from source? Do you have the history of commands, or the list of all dependencies you have added to the server? I'm wondering if you are missing some system dependency or something. capabilities() thinks you have what you need, though...

Also, what happens if you execute something simple like

plot(iris$Sepal.Length, iris$Sepal.Width)

I was unable to reproduce after running

apt-get build-dep r-base

And then compiling R 3.5.1 with

$ ./configure \
  --prefix=/opt/R/$(cat VERSION) \
  --enable-memory-profiling \
  --enable-R-shlib \
  --with-blas \

$ make
$ sudo make install

If you want to try compiling fresh, you could do that. Or you could list the system dependencies you have installed with

apt list --installed

This would at least allow those of us with working systems to see if you're missing one!

EDIT: Looking at your capabilities a bit closer, you are missing cairo, which could be problematic. I think you can install it with apt-get install -y libcairo2-dev? And then you will need to rebuild R.

Hi Cole
Thank you so much for the help. I followed your suggestions in the above post and still got bad luck (same error, cannot start device PNG). I tried to generate the png file in R, it works fine. I cannot attach with the post as a new user. Sorry, but do you have a personal email for me to send the apt list?


How long is it? I would think you would be able to paste it into a code chunk by surrounding in "```"?

Did you try installing libcairo2-dev? Is it present in your list? That may be a quick way to find the problem!

These are all the ‘cairo’ related ones. Yes, they are in the list

libcairo-gobject2/xenial,now 1.14.6-1 amd64 [installed,automatic]

libcairo-script-interpreter2/xenial,now 1.14.6-1 amd64 [installed,automatic]

libcairo2/xenial,now 1.14.6-1 amd64 [installed,automatic]

libcairo2-dev/xenial,now 1.14.6-1 amd64 [installed]

libcairomm-1.0-1v5/xenial,now 1.12.0-1 amd64 [installed,automatic]

Very strange! What if you try to recompile R from source, and add the --with-cairo option (or whatever the syntax is)? Before you make and make install, you should see whether the cairo capability is set up appropriately (it prints right at the end of the configure command).

We have directions (for RHEL) at:

And for a few different architectures at: http://docs.rstudio.com/connect/admin/getting-started.html#r-source

thanks Cole. That actually works for me by rebuilding a fresh R with all the dependencies you mentioned. Cheers!