JSON only...

0 views
Skip to first unread message

Alberto Santini

unread,
Apr 7, 2008, 4:35:15 AM4/7/08
to Rpad
Hello.

I would like to use Rpad (with Yahoo! User Interface - yui) as data
server provider. I would not use Rpad to embed R code in html pages,
but the Rpad server side would provide "only" the data requested from
the frontend in json format.

I am aware about json function in Rpad package and I played with Rpad
examples. Until here there is no problem.

I have been looking for a simple example about "R_process.pl" url
(post option) or "rpad.send" javascript snippet: how to re-use Rpad
framework without the high level Dojo tagging?

(I have been using the local version on Windows Vista).

Thanks in advance for your help,
Alberto

Alberto Santini

unread,
Apr 8, 2008, 6:14:39 AM4/8/08
to Rpad
I found this way (using the local server on Windows Box):

http://127.0.0.1:8079/R_process.pl?&&command=R_commands&R_commands=print("hello")

returning

[1] "hello"

Of course R_commands may contain any R command or user function.
By the way in GET mode, as above, you have to encode the (complex)
params, but I will use post mode.

To receive the result in json format

...&R_commands=json(...what_you_wish...)

Or I could embed the trasformation to json format in the function I am
calling.

The pseudo-sequence diagram for that call, after you started Rpad
server with "Rpad()" is the following:
- mini1.1.tcl - see the line R_eval "processRpadCommands" in the
section R_process.pl
- LocalVersion.R - processRpadCommands() - guiSource(textcommands)
executes the commands

What I don't understand it is the double ampersand in the url: .../
R_process.pl?&&command=...

Next step it's the integration (using that template url as action of a
form, for instance) with YUI.
(I have to check too the passing of the arguments to the user
function).

Thanks in advance,
Alberto

Short, Tom

unread,
Apr 8, 2008, 8:35:06 AM4/8/08
to Rp...@googlegroups.com
I don't know why you need the double ampersand. Likely a bug.


Tom Short
Electric Power Research Institute (EPRI)

Alberto Santini

unread,
Apr 8, 2008, 9:44:19 AM4/8/08
to Rpad
Hello Tom.

Yes, my fault. We can delete the double ampersand. :) Of course I was
sleeping.

And below the snippet to use a json object returned by R using YUI.
Mission accomplished.

<script type="text/javascript">
YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.XHR_JSON = new function() {
var myColumnDefs = [
{key:"a", label:"Col1"},
{key:"b", label:"Col2"},
{key:"c", label:"Col3"}
];

this.myDataSource = new YAHOO.util.DataSource("http://
127.0.0.1:8079/R_process.pl?");
this.myDataSource.connMethodPost = true;
this.myDataSource.responseType =
YAHOO.util.DataSource.TYPE_JSON;
this.myDataSource.responseSchema = {
fields: ["a","b","c"]
};

var args = encodeURIComponent("json(c(a=1, b=5, c=10))");
var postData = "command=R_commands&R_commands=" + args;
this.myDataTable = new YAHOO.widget.DataTable("json",
myColumnDefs, this.myDataSource,
{ caption:"",
draggableColumns:true,
selectionMode:"single",
initialRequest: postData
});

};
});
</script>


On Apr 8, 2:35 pm, "Short, Tom" <TSh...@epri.com> wrote:
> I don't know why you need the double ampersand. Likely a bug.
>
> Tom Short
> Electric Power Research Institute (EPRI)
>

Thanks Tom for your beautiful package.

Regards,
Alberto
Reply all
Reply to author
Forward
0 new messages