[英]How can I load and execute external R scripts in rails
I'm currently using rseve and the rserve-simpler gem. 我目前正在使用rseve和rserve-simpler gem。
Anyone with experience on how to best accomplish this. 有如何最好地做到这一点的经验的人。 Im not tied to a specific gem/lib 我没有绑定到特定的gem / lib
Regards 问候
I've achieved this using the following code 我已经使用以下代码实现了
# setup the data to be used by R scripts
r.>> "data <- c(#{out_data_points})"
# Setup some params for plotting
r.>> "png(file='#{Rails.root}/public#{plot_file_name}')"
r.>> "plot_name <- '#{self.name} : #{label}'"
# call the custom script
r.>> "source('#{Rails.root}/app/rscripts/custom_script.r')"
I send R the data via the data variable and the script must setup variables in R that can be obtained via the converse method within the rails app. 我通过数据变量向R发送数据,脚本必须在R中设置可以通过rails应用程序中的相反方法获得的变量。 Also the images are sent to a specific dir with names dictated by the rails app and passed to the RScript. 同样,图像会被发送到具有由Rails应用程序指定的名称的特定目录,并传递到RScript。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.