From matevzpavlic at gmail.com  Mon Feb 18 21:44:20 2013
From: matevzpavlic at gmail.com (Matevz Pavlic)
Date: Mon, 18 Feb 2013 12:44:20 -0800 (PST)
Subject: [Rd] Passing R code from webpage
In-Reply-To: <70DFF251-F763-40E1-8AC3-443D3291453E@r-project.org>
References: <1361058494221-4658800.post@n4.nabble.com>
	<CAANJ-wek4j+ab=1_0quUGgrnBrf+kRMocFpTodRNCqAFrJEXHQ@mail.gmail.com>
	<BLU166-W35CDC0CE9CC52759F67450BEF40@phx.gbl>
	<1361186683328-4658909.post@n4.nabble.com>
	<676B15E0-CD6B-4E9C-8A29-D2A8EA1699A3@r-project.org>
	<1361200801464-4658944.post@n4.nabble.com>
	<70DFF251-F763-40E1-8AC3-443D3291453E@r-project.org>
Message-ID: <1361220260531-4658988.post@n4.nabble.com>

*Hi, 

first of all-thank you for your extensive answer.*




> Hi, 
> 
> 
>> 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. 
> 
> What do you mean by wrapper? 
> 

>It defines an API that is easier to use that writing the httpd function
(which is called by the build-in HTTP server) yourself.

*OK. Thanks for the clarification.*

> What do you mean by scale/scaling? (not an IT engineer). Mainly this would
> be used for one-user-at-the-time. So if by scaling you mean multiple user
> at
> the same time,



I'm not sure what you really mean ;) - using R from HTML simply means
sending R code from the client (browser) to the server and have the server
run that code. That's easy - you simply issue a request, for example
http://myserver/R?eval=print(1:10)

* I don't know if it should work, but he link with example doesn't work on
my machine.... )*

> For example (this is using FastRWeb API but it should illustrate the
> idea):

*Ok, here's where i lose it.*
/
foo.R:

run <- function(city, ...) {
  if (missing(city)) return("Sorry, you have to specify a city!")
  db <- dbConnect("myDatabase:...")
  q <- dbSendQuery(db, "SELECT age FROM user WHERE city=?", city)
  age <- fetch(q, n = -1)[[1]]
  dbClearResult(q)
  dbDisconnect(db)
  p <- WebPlot(400, 400)
  hist(age)
  p
}/

*Ok, creating a foo.R is easy. But where do i put this file? Do i have to
start the server before or open  R ? *

 
I/n HTML you can either use a form/

/<form action=R/foo>
City: <input type=text name=city>
<input type=submit>
</form>/

*How does HTML know where to "look" for the file foo.R. This is what i can
't see written anywhere in manuals?
*
/
Either way, you get the idea - you could pass a SQL query instead or use
eval() in the argument if you want (as I said, that's too insecure for my
taste). But in all cases you are really running everything server-side.
/

*Ok, this is even better. *

/That said, there is potentially another solution -- I don't know anything
about CSHTML, but if it can really hook into C# from HTML then you make be
able to use the C# part to connect to R - there is a C# Rserve client
(assuming that CSHTML is server-side interpretation). This is theoretical, I
don't use Windows so I don't know if that is meant to work./

*Ok, i'll look at it. *

Thank again, 

matevz
>



--
View this message in context: http://r.789695.n4.nabble.com/Passing-R-code-from-webpage-tp4658800p4658988.html
Sent from the R devel mailing list archive at Nabble.com.



[Rd] Passing R code from webpage
Matevz Pavlic