[R-SIG-Mac] Executing R from perl script called from browser
Simon Urbanek
simon.urbanek at r-project.org
Fri Apr 1 03:04:21 CEST 2011
Carl,
any reason why you're not using more reliable and faster solutions like FastRWeb? ;)
Anyway, your R code is not syntactically legal, so I would not be surprised if you don't see anything (open2 doesn't cover STDERR AFAIR). If I were you, I'd not use embedded code to start with -- you'd make your life (=debugging) much easier if you simply evaluated something like try(source('..foo.R'),silent=TRUE) -- and you don't need such complicated contraptions for that, actually ...
Cheers,
Simon
On Mar 31, 2011, at 6:58 PM, Carl pfisterer wrote:
> I am attempting execute a perl script that calls R from a browser. My test script currently executes the R code which creates a plot as a png and displays the png file in the browser. The perl code executes fine under the command line but the R code does not appear to be called when executed from the browser (png file does not update). I am currently storing the perl script in ~/Sites and calling from the browser by http://localhost/~carlp/htmltest.cgi. When I refresh the browser, top will show perl and R start briefly and although the perl code executes, the R code does not. The R code itself queries a MySQL database though a JDBC connection. The test perl code is as follows:
> #!/usr/bin/perl#htmltest.cgiuse strict;use warnings;use IPC::Open2;use CGI;
> createPlot();printHTML();
> sub createPlot { my @projects = ("Project1","Project2"); my $line = "test";
> my $pid = open2(*READ_R, *WRITE_R, '/usr/bin/R', '--slave', '--silent', '--args', @projects); print WRITE_R " Args = commandArgs(TRUE) source('/Users/carlp/Documents/RWork/QueryFunctions.R'); png('/Users/carlp/Sites/plot.png',height = 600,width = 800); plotDailyByProject(Project = Args,Year=2010,Species = 'Chinook'); dev.off(); q('no') ";
> while ($line = <READ_R>) { chomp $line; #print "[$line]\n"; } close(WRITE_R); close(READ_R);}
> sub printHTML { my $cgi = new CGI; print $cgi->header(),$cgi->start_html("Welcome to htmltest.cgi"); print $cgi->center("Plots Generated in R"); print '<img src="plot.png">'; print $cgi->end_html();}
> I was unsure whether to post this to the mac list since I am using Mac OS X 10.6.7 or to the general help list but I thought I'd try here first. Any suggestions would be greatly appreciated!
> -Carl
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
More information about the R-SIG-Mac
mailing list