image "**.png" cannot be displayed because it contains errors

1,714 views
Skip to first unread message

Kajack

unread,
Jun 27, 2011, 4:45:46 PM6/27/11
to rap...@googlegroups.com
Hi, Below is my Apache settings on Ubuntu 11.04

In /etc/apache2/apache2.conf
====================
LoadModule R_module /usr/lib/apache2/modules/mod_R.so
ROutputErrors
<Location /RApacheInfo>
SetHandler r-info
</Location>
REvalOnStartup "library(brew); library(RJSONIO); library(car); library(Cairo)"
====================

In /etc/apache2/sites-available/default
====================
  Alias /Rscript/ /var/www/R/
  <Directory /var/www/R/>
    Sethandler r-script
    RHandler brew
  </Directory>
====================

My /var/www/R/brew/scatter.html file
===================
<%
path <- "/R/images/test5.png"
full_path <- paste( "/var/www", path, sep="")
Cairo( file=full_path, type="png")
p<-plot( runif(100))
setContentType(type="png")
png( full_path, type="cairo")
print( p)
dev.off()
%>
===================

Image is created good. I can open it in any image viewer program

But when I use the web to see the image, like http://localhost/Rscipt/images/test5.png

ERROR: The image "http://localhost/Rscipt/images/test5.png" cannot be displayed because it contains errors.

ERROR in Firefox Firebug: Image corrupt or truncated http://localhost/Rscipt/images/test5.png

I feel its something to do with rApache.

Any suggestions or recommendations are very helpful.

tcash21

unread,
Jul 28, 2011, 10:00:34 PM7/28/11
to rapache
I'm having the same problem. I can create the png file through
RApache, view it in any image viewer, but the browser cannot seem to
view the file because "it contains errors". Hoping to get a solution
soon.
> But when I use the web to see the image, likehttp://localhost/Rscipt/images/test5.png
>
> ERROR: The image "http://localhost/Rscipt/images/test5.png" cannot be
> displayed because it contains errors.
>
> ERROR in Firefox Firebug: Image corrupt or
> truncatedhttp://localhost/Rscipt/images/test5.png

Jeroen Ooms

unread,
Jul 29, 2011, 3:30:10 AM7/29/11
to rap...@googlegroups.com
Your content type header is incorrect. rtm.




--
You received this message because you are subscribed to the Google Groups "rapache" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rapache/-/X2w__hUbdyUJ.
To post to this group, send email to rap...@googlegroups.com.
To unsubscribe from this group, send email to rapache+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rapache?hl=en.

Aleksandar Blagotić

unread,
Jul 29, 2011, 6:06:21 AM7/29/11
to rap...@googlegroups.com
IMHO, it's not the content-type, it's the brew handler - you're trying to parse an image file with brew() method, and that's what causing the problem. I haven't tested your config, but "RHandler brew" seems a bit odd (shouldn't you put "RHandler brew::brew" instead). And yes, like Jeroen noticed, you also have strange content-type. But is it mandatory to set content-type of an image? I don't think so... Apache deals with that, right? O_o

Anyway... solution: separate img/ folder from the one that contains R scripts. Or use <FilesMatch > directive.

tcash21

unread,
Jul 29, 2011, 8:30:51 AM7/29/11
to rapache
It was as simple as moving the /images directory outside of the /brew
directory. Solved!

On Jul 29, 6:06 am, Aleksandar Blagotić <aca.blago...@gmail.com>
wrote:
> IMHO, it's not the content-type, it's the brew handler - you're trying to
> parse an image file with brew() method, and that's what causing the problem.
> I haven't tested your config, but "RHandler brew" seems a bit odd (shouldn't
> you put "RHandler brew::brew" instead). And yes, like Jeroen noticed, you
> also have strange content-type. But is it mandatory to set content-type of
> an image? I don't think so... Apache deals with that, right? O_o
>
> Anyway... solution: separate img/ folder from the one that contains R
> scripts. Or use <FilesMatch > directive.
>
>
>
> On Fri, Jul 29, 2011 at 09:30, Jeroen Ooms <jeroeno...@gmail.com> wrote:
> > Your content type header is incorrect. rtm.
>

Aleksandar Blagotić

unread,
Jul 29, 2011, 8:45:52 AM7/29/11
to rap...@googlegroups.com
Nice, but note that every single file in /var/www/R/ will be parsed with brew::brew. If you have, say a JS or PHP file alongside R scripts, you will run into errors. <FilesMatch> directive is a beauty, and it's really easy to pass a simple regexp to match files you'd like to parse with brew(). And if you're not writing a spaghetti code (HTML+R with <% %> tags), it's far more useful (and faster) to use base::sys.source

After all... every programmer's problem is just an RT(F)M issue... =)

Jeffrey

unread,
Jul 29, 2011, 12:00:42 PM7/29/11
to rapache


On Jul 29, 7:30 am, tcash21 <tanyac...@gmail.com> wrote:
> It was as simple as moving the /images directory outside of the /brew
> directory. Solved!

tcash21, sweet!

Share a link with us when you get a chance.

Jeff
>
> On Jul 29, 6:06 am, Aleksandar Blagotiæ <aca.blago...@gmail.com>
Reply all
Reply to author
Forward
0 new messages