0

I am trying to integrate r to create a very simple web application using DeployR open 8.0.0 on a Ubuntu machine. I am using the following code on the client side:

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

and the following R code:

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

All that I am getting is a button to upload file and thats it...I dont know where I am going wrong...please help.

Andrie
  • 176,377
  • 47
  • 447
  • 496
  • Are you sure about the syntax? I haven't used `DeployR` but shouldn't the javascript code be like `.end(function(result) {...})` instead of `.end(function(result)) {...}`? – cryo111 Apr 04 '16 at 16:33
  • @cryo111 thanks for pointing that out man, I am very new to javascript :). But unfortunately it doesn't help. I can't figure out what's going wrong...its been 2 days...m kinda losing hope from DeployR :(. – Aniruddha Sanyal Apr 04 '16 at 18:42
  • If you use Firefox, have you Firebug installed? You can use it to find problems with your html/javascript code. If you use Chrome, goto the Devtools Menu `Ctrl+Shift+i`. Then you can at least rule out any html/javascript errors. – cryo111 Apr 04 '16 at 19:07

1 Answers1

0

You can start the log for the deployR and check what actual you are getting using deployr.configure({cors: true, host: 'http://192.168.0.103:8000',logging:true}).

Also, When you click on your upload button, start the developer tools of the browser. You can check where the script is failing.

Anish
  • 114
  • 1
  • 2
  • 10