Unable to start device PNG

2,099 views
Skip to first unread message

Saptarshi Guha

unread,
May 17, 2013, 6:59:13 PM5/17/13
to shiny-discuss
Hello,

I have shiny server running on RHEL5. When I view the URL from my laptop (Firefox/Ubuntu)
I see

http://screencloud.net/v/hwV8

but my friend (Firefox/OS X) views

http://screencast.com/t/FNYRBwwwu

I have Cairo installed on the server.

The url we are viewing is a
users/sguha/telemadi/

i.e a user direcotyr folder in ~/ShinyApp
Do you know why this happens?

Regards
Saptarshi

Saptarshi Guha

unread,
May 17, 2013, 9:37:26 PM5/17/13
to shiny-discuss

I should point out that both people with the "can't state PNG" error were viewing with macbook pro retina screens. I read somewhere that shiny tries to send higher resolution graphs when it detects high resolution clients.

Joe Cheng

unread,
May 21, 2013, 1:53:08 AM5/21/13
to shiny-...@googlegroups.com
Judging from these screenshots, your friend is in a different part of the app than you--are you sure even when looking at the same part of your app, that the two browsers give different results?

Does it say anything else in your app's log file?


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Message has been deleted

Saptarshi Guha

unread,
Dec 10, 2013, 9:31:08 PM12/10/13
to Andy Chu, shiny-discuss

I read somewhere that shiny choose a different DPI for pmg output based on the client resolution. And this is causing some errors in the device.  I think the fix is not too difficult

On Dec 10, 2013 6:29 PM, "Andy Chu" <and...@google.com> wrote:
Did anyone find a solution to this problem?

I have a basically identical screenshot from a user on Mac OS X 10.9 with Chrome Version 32.0.1700.41 beta -- it says "Error: unable to start device PNG" instead of all the plots.

Every one else can view the plots. For example, I am running Chrome 31.0.1650.48 and it works fine (Mac or Linux).

This is very odd to me because I feel like this is a server side error.  But somehow the client is influencing it.  Is shiny that picky about what client is being used?  I remember earlier we had to upgrade from Shiny 0.6 to 0.7 because of an incompatibility in Chrome.  It was a web sockets issue that time.  We are using Shiny 0.8 now.

The Macbook "retina screen" thing sounds plausible to me.  Any further info?

Andy

Andy Chu

unread,
Dec 10, 2013, 9:55:22 PM12/10/13
to saptars...@gmail.com, shiny-discuss
Can you expand on that?  Did you fix it?  Maybe by setting the resolution explicitly somewhere?

BTW here are the errors from logs.  It only happens on certain requests.

Listening on port 20050
Warning in pngfun(filename = filename, width = width, height = height, res = res,  :
  unable to open connection to X11 display ''
Error in X11(paste("png::", filename, sep = ""), g$width, g$height, pointsize,  : 
  unable to start device PNG
Warning in pngfun(filename = filename, width = width, height = height, res = res,  :
  unable to open connection to X11 display ''
Error in X11(paste("png::", filename, sep = ""), g$width, g$height, pointsize,  : 
  unable to start device PNG
Warning in pngfun(filename = filename, width = width, height = height, res = res,  :
  unable to open connection to X11 display ''
Error in X11(paste("png::", filename, sep = ""), g$width, g$height, pointsize,  : 
  unable to start device PNG
Warning in pngfun(filename = filename, width = width, height = height, res = res,  :
  unable to open connection to X11 display ''
Error in X11(paste("png::", filename, sep = ""), g$width, g$height, pointsize,  : 
  unable to start device PNG
Warning in pngfun(filename = filename, width = width, height = height, res = res,  :
  unable to open connection to X11 display ''
Error in X11(paste("png::", filename, sep = ""), g$width, g$height, pointsize,  : 
  unable to start device PNG
Warning in pngfun(filename = filename, width = width, height = height, res = res,  :
  unable to open connection to X11 display ''
Error in X11(paste("png::", filename, sep = ""), g$width, g$height, pointsize,  : 
  unable to start device PNG
Warning in pngfun(filename = filename, width = width, height = height, res = res,  :
  unable to open connection to X11 display ''
Error in X11(paste("png::", filename, sep = ""), g$width, g$height, pointsize,  : 
  unable to start device PNG
Warning in pngfun(filename = filename, width = width, height = height, res = res,  :
  unable to open connection to X11 display ''
Error in X11(paste("png::", filename, sep = ""), g$width, g$height, pointsize,  : 
  unable to start device PNG

  

Andy


Saptarshi Guha

unread,
Dec 11, 2013, 12:55:43 AM12/11/13
to Andy Chu, shiny-discuss
No I didn't solve it, but tracked it down to renderPlot which calls plotPNG which has the following source

function (func, filename = tempfile(fileext = ".png"), width = 400, 
    height = 400, res = 72, ...) 
{
    if (capabilities("aqua")) {
        pngfun <- png
    }
    else if (nchar(system.file(package = "Cairo"))) {
        require(Cairo)
        if (res == 72) {
            pngfun <- Cairo::CairoPNG
        }
        else {
            pngfun <- png
        }
    }
    else {
        pngfun <- png
    }
    do.call(pngfun, c(filename = filename, width = width, height = height, 
        res = res, list(...)))
    tryCatch(func(), finally = dev.off())
    filename
}

IIRC, retina displays have res > 72 and then something bails here.

I expected the shiny devs to fix this but there wasn't any response. 

Cheers
Saptarshi

Stéphane Laurent

unread,
Dec 11, 2013, 6:30:32 AM12/11/13
to shiny-...@googlegroups.com, Andy Chu, saptars...@gmail.com
Try to type 

options(bitmapType="cairo")
 
at the beginning of server.R

Winston Chang

unread,
Dec 11, 2013, 10:23:18 AM12/11/13
to Andy Chu, saptars...@gmail.com, shiny-discuss
Andy, are you running your app locally, or on a remote machine with Shiny Server?

-Winston


Yihui Xie

unread,
Dec 11, 2013, 12:35:04 PM12/11/13
to saptars...@gmail.com, Andy Chu, shiny-discuss
The warning "unable to open connection to X11 display ''" in the png
device is often an indication of having installed cairo without pango
when building R from source. However, if you do have the Cairo package
(http://cran.r-project.org/package=Cairo) installed, you should not
see such warnings.

Regards,
Yihui


On Tue, Dec 10, 2013 at 11:55 PM, Saptarshi Guha

Saptarshi Guha

unread,
Dec 11, 2013, 1:04:42 PM12/11/13
to Yihui Xie, Andy Chu, shiny-discuss
Hello,

I do have Cairo and when library(Cairo) works.
And to answer a question before, this function is being called in my app's server.R (ishinyServer)
Cheers
Saptarshi


Winston Chang

unread,
Dec 11, 2013, 1:21:05 PM12/11/13
to Andy Chu, shiny-discuss
I think Yihui is pointing to correct root cause, which is that your copy of R was compiled without the proper pango support. It also sounds like you also have the Cairo package installed.

The reason that you're only seeing this on some clients is because of a workaround in Shiny that deals with a bug with the Cairo package. Cairo doesn't properly support higher resolutions; `Cairo::CairoPNG` always outputs with 72 pixels per inch (even if a different value is specified), so if CairoPNG is used to create HiDPI images (like for a Retina display), the fonts come out way too small. So Shiny does approximately this (there's actually a little more to it if you're on a Mac):
* If Cairo isn't installed: use R's `png` function.
* If Cairo is installed and the client is using a normal (not HiDPI) display: use R's `png` function.
* If Cairo is installed and the client is using a HiDPI display: use the `Cairo::CairoPNG` function.

This is why you're running into it only with some clients. The source code has comments about this:

If you're seeing the problem only in the second condition, then the problem is likely with how your copy of R was compiled.

-Winston





On Wed, Dec 11, 2013 at 12:01 PM, Andy Chu <and...@google.com> wrote:
The app is running on a Linux box with Shiny 0.8 (without shiny server).  As I was saying, this only happens for *some clients*.  For those clients, it happens with ALL shiny apps, even "01_helloworld" and such.  There are many people using these Shiny apps without any problems.

The Mac Retina theory that Saptarshi points out matches the bug report very well, although I haven't been able to get my hands on a Mac Retina to dig any deeper.

As I was saying, it definitely seems like a server error, but it's actually dependent on the *client*.  The code snippets he pointed to seem plausible as the cause as well.

Andy


Andy Chu

unread,
Dec 11, 2013, 1:33:49 PM12/11/13
to Winston Chang, shiny-discuss
Hm I am not familiar with Pango, but I definitely did compile my own R and install Cairo.  Everything else about Cairo works with R.  I will look at adding the Pango dependency and see if that fixes it.  Thanks for the help.

Andy


Yihui Xie

unread,
Dec 11, 2013, 4:02:32 PM12/11/13
to Andy Chu, Winston Chang, shiny-discuss
I'm not sure about your OS, but in case you use Ubuntu/Debian, you should

sudo apt-get build-dep r-base-dev

to install all the necessary system dependencies before you build R
from source. It is not trivial to figure out everything by looking at
./configure. It is very common for those who build R from source to
omit Pango when installing Cairo.

Regards,
Yihui

Saptarshi Guha

unread,
Dec 11, 2013, 7:58:16 PM12/11/13
to Yihui Xie, Andy Chu, shiny-discuss
And to confirm, i tested this today, accessing the page works from a
Thinkpad X1 Carbon but returns with that error from a MBP Retina.

Very strange.
Thanks for your time
Saptarshi

Andy Chu

unread,
Dec 11, 2013, 9:10:44 PM12/11/13
to Saptarshi Joy Guha, Yihui Xie, shiny-discuss
Did you build your own R?  That theory sounds plausible to me -- it's a combination of the MBP Retina requesting a high resolution and the server side Cairo being "incomplete".  I haven't gotten around to testing it yet.

Yihui, thanks for the tip.  I had avoided doing the full "build-dep" because I was trying to build an "server R" without X11, which would just plot with Cairo (I don't remember if I succeeded, if anyone has any pointers let me know :)  It seems Cairo still has X11 dependencies at least in Debian/Ubuntu? )  But I will try to track down the Pango dependency and rebuild.

Andy



Message has been deleted

Winston Chang

unread,
Jul 26, 2017, 4:22:49 PM7/26/17
to Shiny - Web Framework for R, yi...@rstudio.com, and...@google.com, saptars...@gmail.com
If you're using a Mac that has a Retina display, then it seems likely that the problem you're having is related to image size. When Shiny renders a plot for a client that has a Retina display, it will double the resolution of the output file.

If you use png() to try to create a very large image, it will give an error. (Note that type="cairo" is the default on Linux, but not on Mac.)

> png(width=1000,height=40000, type = "cairo")
Error in png(width = 1000, height = 40000, type = "cairo") : 
  unable to start device 'png'
In addition: Warning message:
In png(width = 1000, height = 40000, type = "cairo") :
  cairo error 'invalid value (typically too big) for the size of the input (surface, pattern, etc.)'


One possible way around this is to use the renderImage() function. Unlike renderPlot(), it will not automatically double the resolution of the output image. See ?renderImage for some examples.

-Winston



On Tuesday, July 25, 2017 at 10:29:29 PM UTC-5, Stephen Hayne wrote:
I know this is very late to this discussion, but I am experiencing EXACTLY this error when serving png(s) from an Azure Ubuntu install of R+Shiny using just apt-get.  My shiny app works perfectly when browsed to by windows (IE/Chrome/FF) or ubuntu (FF), but will gives the "unable to start device 'png'" error on my Mac in both chrome and safari.

The code that gens the png tab pages - that others have used too:

    rl = lapply(sprintf(all), png::readPNG)
    gl = lapply(rl, grid::rasterGrob)
    gridExtra::grid.arrange(grobs=gl, ncol = 6, nrow = 200)

"all" is a nice list of filenames to read...no trouble there...

Very strange.  None of the suggestions about cairo, etc., work for me...

--
Dr. Stephen C. Hayne, Professor, CIS, Colorado State University
    __!__   (970)491-7511(w)  (970)491-5205(f)  (970)204-4040(h)
___(_)___   "I love to fly AngelFlights!  310I - N8109M
Reply all
Reply to author
Forward
Message has been deleted
0 new messages