Ubuntu Server上的Rscript和Nodejs集成 [英] Rscript and Nodejs integration on Ubuntu Server

查看:63
本文介绍了Ubuntu Server上的Rscript和Nodejs集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个节点js应用程序,在其中我调用rscript进行一些统计计算,并返回包含8个元素的数组,然后将其传递回nodejs,以便我们可以在ejs页面上显示这些元素.

I am trying to build a node js app in which i call rscript to do some statistical computation and return an array with 8 elements which then i pass back to nodejs so that we can display those elements on ejs pages .

我能够在本地主机上成功执行此操作,一切正常,甚至rscript正在运行并返回输出,但是当我们尝试在ubuntu服务器上执行相同操作时,我们没有得到任何console.log(out)在我们的终端上(out是从rscript获取输出的变量),我们得到一个null.

I am successfully able to do this on local host everything is working fine and even rscript is running and giving back the output, but when we try to do the same on ubuntu server we are not getiing any console.log(out) on our terminal (out is the variable which gets the output from the rscript) we get a null.

我们在本地主机和服务器中调用脚本的方式与所示相同.

We are calling the script in localhost and server in same way as shown.

`console.log(data);
var out = rscript(abc.R)
.data(data.xyz,data.abc)
.callSync();
console.log(out);`

在上面的代码中,我们在data变量中获取了json,并且它还提供了本地和服务器上的日志.

In the above code we get json in the data variable and it gives log as well both on local and server.

我已经使用npm在nodejs中安装了所有需要的库,例如rscirpt,并且已经在我的ubuntu服务器上安装了R和Rstudio,还安装了运行rscript所需的所有库.

I have installed all the libraries needed like rscirpt inside nodejs using npm and have already installed R and Rstudio on my ubuntu server and installed all the libraries too which are needed to run the rscript.

rscript放置在我的index.js所在的文件夹中,而ejs页面存储在节点应用程序也可以访问并显示它们的其他文件夹中.

The rscript is placed in same folder where my index.js is alll the ejs pages are stored in other folder which the node app is able to access and display them too.

推荐答案

您将不得不将R脚本部署到其他地方,然后使用节点服务器文件中的API调用来调用R脚本.

You will have to deploy your R script somewhere else and then call that R script using API calls in your node server file.

Algorithmia是可用于在节点中将rscript作为API调用的服务之一.您只需要遵循他们的指示并将所有代码包装在一个函数中即可.创建R项目后,它将作为示例出现在这里.

One of the services that you can use to call rscript as an API in node is Algorithmia. You will just need to follow their instructions and wrap all your code inside a function. It will appear as a sample there, once you create an R project.

这篇关于Ubuntu Server上的Rscript和Nodejs集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆