什么是部署结合R的功能和一个API,最简单的方法? [英] What's the easiest way to deploy an API incorporating R functions?

查看:180
本文介绍了什么是部署结合R的功能和一个API,最简单的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要从以下变量约50000罪的数据帧当地犯罪API;犯罪类型的一个因素,在犯罪的日期,经纬度。

I want to make a local crime API from a data frame of about 50,000 crimes with the following variables; crime type as a factor, the date of the crime, and latitude and longitude.

我想用我的体型在我的功能选择一个时间范围,犯罪类型,以及最重要的只返回给定范围内发生的犯罪,从一个给定的lat和长。

I want to use my build in my functions for choosing a time range, crime type, and most importantly returning only crimes that occurred within a given radius from a given lat and long.

我有我自己学会了如何使用GET和POST一个API和R对象和JSON之间进行转换,但我不知道很多关于构建的API。如果有人请我提供一点方向上轻松实现通过一个Web服务,将是巨大的主办。免费托管试验将是preferred但如果有一个简单的方法来实现这一目标的一个微不足道的价格是凉爽。

I have learned on my own how to use GET and POST for an api and converting between R objects and json but I don't know much about building an api. If someone please provide me a little direction on an easy implementation to be hosted by a web service that would be great. Free hosting for experimenting would be preferred but if there is a simple way to make this happen for a trivial price that is cool to.

感谢

推荐答案

对于一个简单的API调用,我认为最好是使用 RApache
安装RApache如 http://rapache.net/manual.html

For a simple API call, I believe the best is to use RApache. Install RApache as indicated in http://rapache.net/manual.html

设置在httpd.conf Apache的指令,它会确保在/ var / WWW / BREW的所有文件都被解析为R脚本

Set the Apache directive in httpd.conf which will make sure all files under /var/www/brew are parsed as R scripts

<Directory /var/www/brew>
    SetHandler r-script
    RHandler brew::brew
</Directory>

您的API让你ř例如脚本mycrimeapi.R并把它在/ var / WWW / BREW文件夹下。该R脚本文件如能如下所示:

Make your R script with your API e.g. mycrimeapi.R and put it under the /var/www/brew folder. This R script file can e.g. look as follows:

<%
require(jsonlite)
load("yourdataset.RData") # this contains your crimes data frame
mycrimes <- subset(crimes, crimetype %in% GET$crime & crimedate %in% as.Date(GET$crimedate))
cat(toJSON(mycrimes))
%>

现在有人可以通过调用调用您的API <$c$c>http://localhost/brew/mycrimeapi.R?crime=crimewhichisreallynasty&crimedate=2014-01-01.与你在哪里托管API服务器的IP localhost替换。

Now someone can call your API by calling http://localhost/brew/mycrimeapi.R?crime=crimewhichisreallynasty&crimedate=2014-01-01. Replace localhost with the IP of the server where you are hosting the API.

在使用RApache,每次得到的时间 GET,POST,饼干,文件,它被传递到API调用服务器变量。所以,如果你想在你的电话,而不是GET例如使用POST,勇往直前。请参阅 http://rapache.net/manual.html 的文档,这些变量。

When using RApache, each time you get GET, POST, COOKIES, FILES, SERVER variables which were passed on to the API call. So if you want to use POST in your call instead of the GET example, go ahead. See the documentation in http://rapache.net/manual.html for these variables.

这篇关于什么是部署结合R的功能和一个API,最简单的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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