Search code examples
javascriptjqueryangularjsropencpu

object Object displayed in html page


I'm trying to display the graph plotted by the R function in the opencpu server. However,it only displays [object Object] in the html page. The following is the code in my AngularJS controller.

var req = ocpu.rpc("plotGraph", {
                filepath:"C:/Users/abc/Desktop/test.txt"
            }, function(output){
              $("#output").text(output);
            }); 

The following is the R function in the package plotGraph.

plotGraph <- function(filepath) {
  test.ecg <- read.table(filepath, quote="\"", comment.char="")
  ecg=ts(test.ecg)
  plot(ecg)

}

How do I display the plot created by the R function?


Solution

  • Try with rplot:

    var req = $("#output").rplot("plotGraph", {
        filepath:"C:/Users/abc/Desktop/test.txt"
    });
    

    ocpu.rpc is to get back json only.