How to call an R script from within a JS code

LabKey Support Forum (Inactive)
How to call an R script from within a JS code Ben Bimber  2012-05-02 11:04
Status: Closed
 
Hi Leo,

Sorry, misunderstood part of your first post. The showSection param allows you to specify which sections of the R report are displayed. For example, your report might have a PNG, some text, and the console output. In your R script, you might have created an output like:

write.table(theTable, file = "${tsvout:tsvfile}", sep = "\t", qmethod = "double", col.names=NA)

or

png(filename="${imgout:barchart}",
    width=1100,
    height=(500),
    #type="cairo"
    );


You'll see I gave names to these outputs. In the webpart config, I provided a comma separated list:

showSection: 'barchart&tsvfile',

which causes only those 2 sections to be shown.

To get at your problem: the best idea we've come up with would be to render the R report to a hidden DIV, and to use showSection to render only the minimal section(s). If you need to pass information from R to JS, you could get your script to output some text when complete, like 'Report Succeeded' or 'Report Failed'. In the success callback from this report webpart, you could use JS to inspect the contents of the DIV where the R report was rendered, and look for these strings. This leaves something to be desired, but may unblock your scenario. Let me know if you'd like more detail on any of this.

The idea of a more direct way to call scripts from JS (and perhaps to parse their results) has come up before. It would be nice to be able do this better.