2016-04-04 24 views
0

我正在嘗試集成r以在Ubuntu機器上使用DeployR open 8.0.0創建一個非常簡單的Web應用程序。我使用在客戶端下面的代碼:DeployR JavaScript API

<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)) 

所有,我得到的是一鍵上傳文件,這就是它...我不知道我要去哪裏錯了...請幫助。

+0

你確定語法嗎?我沒有使用'DeployR',但是不應該像'.end(function(result){...})'而不是'.end(function(result)){...}'? – cryo111

+0

@ cryo111感謝您指出,男人,我很新的JavaScript :)。但不幸的是它並沒有幫助。我無法弄清楚發生了什麼問題......它已經2天了......有點從DeployR中失去希望:(。 –

+0

如果你使用Firefox,你安裝了Firebug嗎?你可以用它來查找你的html/javascript code。如果你使用Chrome瀏覽器,轉到Devtools Menu'Ctrl + Shift + i',那麼你至少可以排除任何html/javascript錯誤。 – cryo111

回答

0

您可以啓動deployR的日誌並檢查使用deployr.configure({cors:true,host:'http://192.168.0.103:8000',logging:true})得到的實際結果。

此外,當您點擊上傳按鈕時,啓動瀏覽器的開發者工具。你可以檢查腳本失敗的地方。