Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Statistical Analysis via Browser

by chunlou (Curate)
on Jun 18, 2003 at 23:20 UTC ( #267025=CUFP: print w/ replies, xml ) Need Help??

This is apparently a special interest topic. In case you ever need to do statistical analysis that's beyond the scope of Perl, R is pretty much the number one Open Source statistical software to use (but lacks well-established interfaces with other languages, while some "under-development" ones mostly for Linux can be found at Omegahat).

And in case you ever have some sales people ask you to recompute something all the time and email them the results in spreadsheet, you may simply want to put the stuff up on the intranet and let them do the computation themselves via a browser.

Hence come Perl and R. Here a sample CGI script, in case you're still interested:

#---------------------File Name: simpleR.pl------------------- #! /usr/local/bin/perl -w use Apache::Request () ; use strict ; # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # You only need to modify this: my $Rpath = "C:\\R\\rw\\bin\\" ; # path to rterm.exe # The rest will hopefully run itself. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # to execute R cmd: R($Rpath, $R_cmd) sub R { my $Rpath = shift ; my $Rcmd = $Rpath . "rterm --vanilla --quiet --slave" ; my $Rscript = shift ; $Rscript =~ s/(\r|;\r)/ ;/gm ; $Rscript =~ s/<-/=/gm ; # \r or +<- break "echo" return `echo $Rscript | $Rcmd` ; } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - my $r = shift ; # Apache stuff my $q = Apache::Request->new($r) ; # Apache Query obj my $command = $q->param('command') ; my $result = $command ? R($Rpath, $command) : "You didn't input any co +mmand." ; # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - print "Content-type: text/html\n\n"; print <<"EOF"; <html><body> <form method="get" action="./simpleR.pl"> Please enter your R command:<br> <textarea rows="4" name="command" cols="60">$command</textarea +><br> <input type="submit" value="Submit"> </form><br> <textarea rows="10" name="result" cols="80">$result</textarea> </body></html> EOF exit;

Comment on Statistical Analysis via Browser
Download Code
Re: Statistical Analysis via Browser
by particle (Vicar) on Jun 19, 2003 at 13:08 UTC

    you've reminded me i should take a closer look at R, thanks for the link. you've also shown me how easy it is to break in to your system :(

    please untaint all user input in cgi scripts. you've opened the door to your system, as arbitrary commands can now be passed directly, as long as they don't include '\r' or '<-'.

    you can look at Ovid's http://users.easystreet.com/ovid/cgi_course for a good web security tutorial, and Super Search around here on words like 'taint' for more on this important subject.

    ~Particle *accelerates*

Re: Statistical Analysis via Browser
by Itatsumaki (Friar) on Jun 19, 2003 at 14:53 UTC

    I'm curious why you chose to use rterm instead or the batch mode for R, Rcmd? I've always used Rcmd because it seems to get slightly better performance.

    -Tats
      Because I wasn't thinking. Just did whatever worked the first time. Thanks for all the considerate advises.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://267025]
Front-paged by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2014-07-11 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (224 votes), past polls