[Rd] Passing R code from webpage
Matevz Pavlic
matevzpavlic at gmail.com
Mon Feb 18 21:44:20 CET 2013
*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.
More information about the R-devel
mailing list