我正在尝试集成 r 以在 Ubuntu 机器上使用 DeployR open 8.0.0 创建一个非常简单的 Web 应用程序。我在客户端使用以下代码:
<html>
<head><script src="./js-client-library-7.4.3/browser/deployr.min.js"></script></head>
<body>
<script>
deployr.configure({cors: true, host: 'http://192.168.0.103:8000'})
var file = document.getElementById('csv-file').files[0]
deployr.auth('testuser','Aniruddha123')
.io('/r/repository/file/upload')
.attach(file, 'defects.csv')
.io('/r/repository/script/execute')
.data({filename: 'forestPredict.R', author: 'testuser', directory: 'root'})
.end(function(result){
ws = result.data.deployr.response.workspace;
var preds = ws.objects[0].value;
var error = ws.objects[1].value;
document.write('<p>'+preds+'</p>'+'ERROR:' error)
})
</script>
</body>
</html>
和以下R代码:
.libPaths( c( .libPaths(), "/home/aniruddha/R/x86_64-pc-linux-gnu-library/3.2") )
library(randomForest)
defects = read.csv('defects.csv')
train = defects[is.na(defects$bugs)]
test = defects[!is.na(defects$bugs)]
forestTest = randomForest(bugs~.,train[-1])
preditions = predict(forestTest, test[-1])
test$bugs = round(preditions)
result = rbind(train, test)
trainPreds = predict(forestTest, train[-1])
meanError = mean(abs(train$bugs - trainPreds))
我得到的只是一个上传文件的按钮,就是这样......我不知道我哪里出错了......请帮忙。