Integration of R and its graphics with an existing Javascript / HTML application

I have an existing Javascript / HTML application. I wanted to harness the power of R Programming

scientific computing and graphics.

My goal -

  • Send some data from Javascript app.
  • Providing predefined R functions using data input.
  • Get the output, get the result in the form of text and graphics.
  • Display it in HTML page.

How to achieve this,

  • Should I run R continuously, use something like web sockets

    and connect to R? If you are doing How to pass R scripts to execute and get the output packet?

  • Rserve . There Rserve

    is some implementation for nodeJS

    . But the problem with this is that every line of code must be passed through commands evaluate

    . Even if I do this, how do I handle the plot output?

  • I did some research on openCPU . If you are using the openCPU R package, R has to run the library continuously opencpu

    , and they each run R and openCPU, it starts at a different port number. And if I close the R session, the server opencpu

    exits as well.

  • If I install a standalone server opencpu

    on my machine, how do I use R with this? I installed a standalone openCPU server and got stuck somehow after that.

How should I proceed, what should I do to complete my task. I don’t seem to know which direction to go. Please shed some light on this. I'm sure most people will need this.

Update:

I worked with shiny

, but in this case, I cannot use it. You need to connect R to an external web application.

Thanks in advance,

Manoj G

+3


source to share


2 answers


FastRWeb sounds like it would be perfect for your needs. From the documentation:

FastRWeb is a framework that allows any web server to use R scripts to generate content on the fly, such as web pages or graphics. URLs are mapped to scripts and can have optional arguments that are passed to the R function from the script. For example http: //my.server/cgi-bin/R/foo.png? N = 100 will make FastRWeb look like up script foo.png.R, type it in and call run (n = "100") ... So for example a script can be as simple as

run <- function(n=10, ...) {
   p <- WebPlot(800, 600)
   n <- as.integer(n)
   plot(rnorm(n), rnorm(n), col=2, pch=19)
   p
}

      



This can then be called with JavaScript to dynamically load the images and display them.

You may also like shiny , although this is a more complete solution.

+2


source


You can use R effectively from javascript using the package Rserve

. There is javascript available for the Rserve rserve-js client .
Also, you might find it interesting to implement httupv

R as a service as described in this Suggestions needed to build REST APIs for an R server that I can call from an external application? ...



0


source







All Articles