Passing R code from webpage

classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Passing R code from webpage

Matevz Pavlic
Hi all,

Is there a way to pass R code from web page (html file) to do some statistics and than plot the output in web browser.

I am looking forever at this, and cant find a way.

Regards,m
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Pulkit Mehrotra
hi ,

First of all you should as this question on r-help rather than on r-devel
as this group deals with development related issues with R.

As for the package you can use the shiny package from Rstudio. I have
provided the links below.

http://shiny.rstudio.org/
http://www.rstudio.com/shiny/

regards,
Pulkit

On Sat, Feb 16, 2013 at 3:48 PM, Matevz Pavlic <[hidden email]>wrote:

> Hi all,
>
> Is there a way to pass R code from web page (html file) to do some
> statistics and than plot the output in web browser.
>
> I am looking forever at this, and cant find a way.
>
> Regards,m
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Pierre Chausse
In reply to this post by Matevz Pavlic
If R and ghostcript are installed on the server that hosts you webpage,
it is easy. All you need is a minimum of php. I started with doR (which
I think does not exist anymore) and modified it. Even better, some
people offers a solution for you. Here is a GPL licenced solution.

http://steve-chen.net/document/r/r_php



Le 2013-02-16 18:48, Matevz Pavlic a écrit :

> Hi all,
>
> Is there a way to pass R code from web page (html file) to do some
> statistics and than plot the output in web browser.
>
> I am looking forever at this, and cant find a way.
>
> Regards,m
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Marc Schwartz-3
In reply to this post by Matevz Pavlic
On Feb 16, 2013, at 5:48 PM, Matevz Pavlic <[hidden email]> wrote:

> Hi all,
>
> Is there a way to pass R code from web page (html file) to do some
> statistics and than plot the output in web browser.
>
> I am looking forever at this, and cant find a way.
>
> Regards,m



You might have wanted to start by looking at the R FAQ, which contains the following:

  http://cran.r-project.org/doc/FAQ/R-FAQ.html#R-Web-Interfaces

More recently, there is Shiny, which I did not see listed in the above:

  http://www.rstudio.com/shiny/

Regards,

Marc Schwartz

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Simon Urbanek
In reply to this post by Matevz Pavlic
On Feb 16, 2013, at 6:48 PM, Matevz Pavlic wrote:

> Hi all,
>
> Is there a way to pass R code from web page (html file) to do some
> statistics and than plot the output in web browser.
>
> I am looking forever at this, and cant find a way.
>

Typically this is done by sending an AJAX request to R and display the result (or simple forms if you want to). I use FastRWeb for this - it even has an example on how you create plots and other output. There is also rApache if you are using apache web server.

Cheers,
Simon


> Regards,m
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Mike Marchywka





----------------------------------------

> From: [hidden email]
> Date: Sun, 17 Feb 2013 09:16:57 -0500
> To: [hidden email]
> CC: [hidden email]
> Subject: Re: [Rd] Passing R code from webpage
>
> On Feb 16, 2013, at 6:48 PM, Matevz Pavlic wrote:
>
> > Hi all,
> >
> > Is there a way to pass R code from web page (html file) to do some
> > statistics and than plot the output in web browser.
> >
> > I am looking forever at this, and cant find a way.
> >
>
> Typically this is done by sending an AJAX request to R and display the result (or simple forms if you want to). I use FastRWeb for this - it even has an example on how you create plots and other output. There is also rApache if you are using apache web server.

Depending on how you want to use it, as others have suggested, there are a lot of approaches. Invoking an "R" process is a bit expensive and
having a single R server available is much more efficient however for what we were doing the bigger gain was from caching results. That is,
we have maps by area, say state or zip code, where we can tolerate results a few minutes old. So, we used a custom java server to
invoke R as part of a general ability to execute bash scripts and then buffer the resulting images in memory. This approach worked well
but did potentially require starting a new Rprocess for each request. I had always wanted to make use of shared R instances but never
got around to doing this as the scaling never became relevant. 

Our interface was something simple, like "http://host/Rscriptname?zip=00000&otherkeys=value"

which would return an result with appropriate mime type to keep browser happy and have it fit on page ok etc.

The point is that  anything that can invoke a bash script can invoke R and if  you are concerned about doing this efficiently it is not hard to write a simple java app that listens on a port and can invoke
R and then do caching to meet your needs if apache etc does not do this easily. 







>
> Cheers,
> Simon
>
>
> > Regards,m
> >
> >
> >
> > --
> > View this message in context: http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800.html
> > Sent from the R devel mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
> >
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
     
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Simon Urbanek

On Feb 17, 2013, at 9:29 AM, Mike Marchywka wrote:

>> From: [hidden email]
>> Date: Sun, 17 Feb 2013 09:16:57 -0500
>> To: [hidden email]
>> CC: [hidden email]
>> Subject: Re: [Rd] Passing R code from webpage
>>
>> On Feb 16, 2013, at 6:48 PM, Matevz Pavlic wrote:
>>
>>> Hi all,
>>>
>>> Is there a way to pass R code from web page (html file) to do some
>>> statistics and than plot the output in web browser.
>>>
>>> I am looking forever at this, and cant find a way.
>>>
>>
>> Typically this is done by sending an AJAX request to R and display the result (or simple forms if you want to). I use FastRWeb for this - it even has an example on how you create plots and other output. There is also rApache if you are using apache web server.
>
> Depending on how you want to use it, as others have suggested, there are a lot of approaches. Invoking an "R" process is a bit expensive and
> having a single R server available is much more efficient however for what we were doing the bigger gain was from caching results. That is,
> we have maps by area, say state or zip code, where we can tolerate results a few minutes old. So, we used a custom java server to
> invoke R as part of a general ability to execute bash scripts and then buffer the resulting images in memory. This approach worked well
> but did potentially require starting a new Rprocess for each request. I had always wanted to make use of shared R instances but never
> got around to doing this as the scaling never became relevant.
>
> Our interface was something simple, like "http://host/Rscriptname?zip=00000&otherkeys=value"
>
> which would return an result with appropriate mime type to keep browser happy and have it fit on page ok etc.
>
> The point is that  anything that can invoke a bash script can invoke R and if  you are concerned about doing this efficiently it is not hard to write a simple java app that listens on a port and can invoke
> R and then do caching to meet your needs if apache etc does not do this easily.
>

That's why FastRWeb gives you all the flexibility without the need to write anything: you can use any webserver you want (with CGI or PHP) or you can use the built-in webserver in Rserve if you don't want any dependencies other than R and it still scales fairly well as it supports parallel connections. You don't need to write anything at all as FastRWeb does all the transformation of URL query parameters, forms etc into R function arguments so you just write scripts with one R function - that simple.

Cheers,
Simon


>
>
>>
>> Cheers,
>> Simon
>>
>>
>>> Regards,m
>>>
>>>
>>>
>>> --
>>> View this message in context: http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800.html
>>> Sent from the R devel mailing list archive at Nabble.com.
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>>
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>    
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Matevz Pavlic
Hi ,

thanks for all the replies.
I'll have a good look at this FastRWeb.  Just one thing. My pages are done with Razor *.CSTHML. Could this be a problem for FastRWeb (and me) ;)?

regards, m
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Simon Urbanek
On Feb 17, 2013, at 11:30 AM, Matevz Pavlic wrote:

> Hi ,
>
> thanks for all the replies.
> I'll have a good look at this FastRWeb.  Just one thing. My pages are done
> with Razor *.CSTHML. Could this be a problem for FastRWeb (and me) ;)?
>

R doesn't care how you generate the pages - it will be just processing requests that you define on such pages. Think of it as serving R scripts by a web server - it doesn't matter how you construct the URLs/requests that reference it.

BTW: since you mentioned CSHTML  --- you'll lose a lot of benefits on Windows, so if you think of using Windows as a server, think twice ;). Pretty much all scalable solutions assume you are using unix. On Windows you'll need a pool of R instances if you want to have some illusion of scalability so it's a lot more involved and wasteful.

Cheers,
Simon



> regards, m
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658839.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Matevz Pavlic
Hi,

yes, i saw that about Cshtml...but it's done already, can't change it now.

Are there any samples of web pages or some samples to download for FastRWeb? I am having troubles understanding how to install this and get it to work...

tnx, m
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Simon Urbanek

On Feb 17, 2013, at 12:09 PM, Matevz Pavlic wrote:

> Hi,
>
> yes, i saw that about Cshtml...but it's done already, can't change it now.
>
> Are there any samples of web pages or some samples to download for FastRWeb?
> I am having troubles understanding how to install this and get it to work...
>

There is the INSTALL file in the package with all the details. Sample scripts (example*) will be installed as part of the installation process -- if you want to look at them first, they are in the inst/web.R directory of the package sources. An example HTML page with JS to use AJAX is in the web/index.html file. Jay Emerson also has a blog entry about installing FastRWeb
http://jayemerson.blogspot.com/2011/10/setting-up-fastrwebrserve-on-ubuntu.html
You can ask questions about FastRWeb or Rserve on the stats-rosuda-devel mailing list.

Cheers,
Simon

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Jeffrey Ryan
Another really great tool, leveraging Simon's incredible work with Rserve,
is to use pyRserve.  Combined with Flask as a web framework you can do
quite a bit with very minimal code.

http://flask.pocoo.org/
http://pypi.python.org/pypi/pyRserve/

HTH
Jeff


On Sun, Feb 17, 2013 at 12:10 PM, Simon Urbanek <[hidden email]
> wrote:

>
> On Feb 17, 2013, at 12:09 PM, Matevz Pavlic wrote:
>
> > Hi,
> >
> > yes, i saw that about Cshtml...but it's done already, can't change it
> now.
> >
> > Are there any samples of web pages or some samples to download for
> FastRWeb?
> > I am having troubles understanding how to install this and get it to
> work...
> >
>
> There is the INSTALL file in the package with all the details. Sample
> scripts (example*) will be installed as part of the installation process --
> if you want to look at them first, they are in the inst/web.R directory of
> the package sources. An example HTML page with JS to use AJAX is in the
> web/index.html file. Jay Emerson also has a blog entry about installing
> FastRWeb
>
> http://jayemerson.blogspot.com/2011/10/setting-up-fastrwebrserve-on-ubuntu.html
> You can ask questions about FastRWeb or Rserve on the stats-rosuda-devel
> mailing list.
>
> Cheers,
> Simon
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



--
Jeffrey Ryan
[hidden email]

www.lemnica.com

R/Finance 2013: Applied R in Finance
May 17, 18 Chicago, IL
www.RinFinance.com

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Matevz Pavlic
This post was updated on .
In reply to this post by Simon Urbanek
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Matevz Pavlic
This post was updated on .
Here's what i did (Windows) :

1.)  install.packages("FastRWeb")  
2.) system(paste("cd",system.file(package="FastRWeb"),"&& install.sh")
3.) code{system.file("cgi-bin", package="FastRWeb")

I ran all this from Rstudio.

I guess it's not enough, because Index.html is empty.


What i don't understand is what "var" means. I suspect it's a folder, probably in unix...because i don't have it anywhere in FastRWeb.

Any help?

Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Mike Marchywka
In reply to this post by Pulkit Mehrotra



----------------------------------------

> Date: Sun, 17 Feb 2013 04:27:38 -0800
> From: [hidden email]
> To: [hidden email]
> CC: [hidden email]
> Subject: Re: [Rd] Passing R code from webpage
>
> hi ,
>
> First of all you should as this question on r-help rather than on r-devel
> as this group deals with development related issues with R.

Well, personally this potentially a rather substantial issue and while methods
may exist to interface R to webservers, it may be worth discussing if there are
any things you could do to R to make it run more easily as an "R" server
so that you need not make a bunch of instance to run in this setting.
If 10 people on the same machine use R, what duplication is there?
Can I launch a background task within R and still work in foreground?
Is there anything anyone could should or wants to change in R to make this
work better here? 


>
> As for the package you can use the shiny package from Rstudio. I have
> provided the links below.
>
> http://shiny.rstudio.org/
> http://www.rstudio.com/shiny/
>
> regards,
> Pulkit
>
> On Sat, Feb 16, 2013 at 3:48 PM, Matevz Pavlic <[hidden email]>wrote:
>
> > Hi all,
> >
> > Is there a way to pass R code from web page (html file) to do some
> > statistics and than plot the output in web browser.
> >
> > I am looking forever at this, and cant find a way.
> >
> > Regards,m
> >
> >
> >
> > --
> > View this message in context:
> > http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800.html
> > Sent from the R devel mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
     
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Matevz Pavlic
Hi,

i think all of this i kinda complicated, even though in all the packages authors  are saying that "minimum code is required".
I mean, i am not an IT engineer , but i have created quite some webpages, so i have some knowledge of HTML5, CSS, C# (limited), and also work quite a lot with R and still installing R to run as a webserver seems to be too complicated.
I have look in all packages i can imaggine, Rook, ggoleVis, Shiny....but in all i get the problem when i want to connect to a MS SQL database.


This is the workflow that i'd like to achieve :
1.) in webrowser connect to MS SQL database
2.) do some R statistics and plots
3.) show that in web browser.


I am pretty sure it can be very complicated, but it just seems so.

any help (still) greatly appreciated.

BTW: I HAVE posted in R-help, but no responses were given.
m

regards, m
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Mike Marchywka




----------------------------------------

> Date: Mon, 18 Feb 2013 03:24:43 -0800
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [Rd] Passing R code from webpage
>
> Hi,
>
> i think all of this i kinda complicated, even though in all the packages
> authors are saying that "minimum code is required".
> I mean, i am not an IT engineer , but i have created quite some webpages, so
> i have some knowledge of HTML5, CSS, C# (limited), and also work quite a lot
> with R and still installing R to run as a webserver seems to be too
> complicated.
> I have look in all packages i can imaggine, Rook, ggoleVis, Shiny....but in
> all i get the problem when i want to connect to a MS SQL database.
>
>
> This is the workflow that i'd like to achieve :
> 1.) in webrowser connect to MS SQL database
> 2.) do some R statistics and plots
> 3.) show that in web browser.

Well, if you want a version of R that is a webserver that is one thing,
if you want a webserver that can call R and don't care how it scales then any server
that can execute arbitrary executables would work and you could ask on an apache list
for example. The problem is getting scaling. In the case we had, results were easily cached
and we had a facility for invoking bash scripts and so t the time the R instances were not a big
deal. There are several ways, like Rserve, to make R more server like. The case we had was mostly loaded
with short requests so we needed to fix the server threading model and used netty and java.
You may be happy with apache, no idea. This becomes an issue of R devel if anyone things 
there are ways to make multiple R tasks work together better.

Accessing DB from R is probably a help question however :) Although here too scaling can be a matter
of caching facilities and a custom server may help there. 




>
>
> I am pretty sure it can be very complicated, but it just seems so.
>
> any help (still) greatly appreciated.
>
> BTW: I HAVE posted in R-help, but no responses were given.
> m
>
> regards, m
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658909.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
     
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Matevz Pavlic
Yes,

i have looked at apache, but  there is no Windows version (at least to my knowledge).

I know how to connect to MS SQL from R, i just dont know how to do that from web browser.

thanks, m
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Mike Marchywka




----------------------------------------
> Date: Mon, 18 Feb 2013 04:13:25 -0800
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [Rd] Passing R code from webpage
>
> Yes,
>

y
> knowledge).

well, this getting off topic but I could suggest you go get cygwin and learn to use linux
while still on 'dohs LOL I think there is a 'dohs apache version but yes it is unlikely
that IIS would interface to stuff like this easily although i have no idea. 


>
> I know how to connect to MS SQL from R, i just dont know how to do that from
> web browser.

If you can do this it is likely a security flaw. You should do all of this on the server.
This has nothing to do with R...



>
> thanks, m
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658915.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
     
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Passing R code from webpage

Simon Urbanek
In reply to this post by Matevz Pavlic
On Feb 18, 2013, at 6:24 AM, Matevz Pavlic wrote:

> Hi,
>
> i think all of this i kinda complicated, even though in all the packages
> authors  are saying that "minimum code is required".
> I mean, i am not an IT engineer , but i have created quite some webpages, so
> i have some knowledge of HTML5, CSS, C# (limited), and also work quite a lot
> with R and still installing R to run as a webserver seems to be too
> complicated.

Not at all - R has a built-in webserver (it's used for the help pages), so if you install R, you're done with that part. Rook gives you a wrapper for that.

The problem is it doesn't scale, so if you're happy with one-user solution then you can use R without anything. If you need something that scales, then you need something else -- and for Windows you're a bit out of luck, because the lack of fork+COW on Windows (BTW cygwin doesn't help there, either) paired with the fact that R is not thread-safe means it's quite hard to get scalability on Windows involving R. The best bet on Windows are server solutions that keep a pool of individual R instances as workers but I'm not aware of any off the top of my head (I recall some Java solutions way back when Java was hip and I have it on my ToDo list for Rserve but it's not there yet).


> I have look in all packages i can imaggine, Rook, ggoleVis, Shiny....but in
> all i get the problem when i want to connect to a MS SQL database.
>

That shouldn't really matter - as long as you can connect from any R session, you will be able to connect through R from the webserver.


> This is the workflow that i'd like to achieve :
> 1.) in webrowser connect to MS SQL database

I assume you mean from the R script? Otherwise you'll have to shove the data across (not impossible but why not connect from R?).


> 2.) do some R statistics and plots
> 3.) show that in web browser.
>
>
> I am pretty sure it can be very complicated, but it just seems so.
>
> any help (still) greatly appreciated.
>
> BTW: I HAVE posted in R-help, but no responses were given.
> m
>
> regards, m
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658909.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
12