Giter Site home page Giter Site logo

mlds-couchdb-demo's Introduction

DeployR - R Analytics Integration

Same DeployR enabled R Script, diffrent client.

This example can be used in conjunction with the mlds-ui-demo to demonstrate how a different DeployR consumer/client can invoke the same R Script /sheri/geo/RUGclusters.R and do something different with the result. For this example, the geoJSON returned from calling /sheri/geo/RUGclusters.R is stored in CouchDB rather than building a UI as we did in mlds-ui-demo.

Prerequisites

  • Install the latest stable version of Node.js (version 0.10.x).
  • Install CouchDB

Quick start

  1. Install Node.js
  2. Install CouchDB
  3. Create a new Database named feature from the CouchDB Admin Console
  4. $ git clone https://github.com/mlds-deployr/mlds-couchdb-demo.git
  5. $ cd mlds-couchdb-demo
  6. $ npm install
  7. $ node index.js This runs the demo.
  8. Open the CouchDB Admin Console and view the newly inserted geoJSON returned from executing the R Script /sheri/geo/RUGclusters.R under the feature Database.
var deployr    = require('deployr').configure({ host: 'http://166.78.105.110:7400' }),
    stream     = require('stream')
    JSONStream = require('JSONStream'),
    got        = require('got'),
    nano       = require('nano')('http://localhost:5984'),
    feature    = nano.db.use('feature');

//
// Stream Transform duplex to download DeployR response artifact URLs in 
// geoJSON and store it in CouchDB
//
var geo = new stream.Transform({ objectMode: true });

geo._transform = function(chunk, encoding, done) {
    var data = chunk.toString();

    if (data) {
        got.get(data.replace(/\"/g, ''))
            .pipe(feature.insert(null, 'feature'));
    }

    done();
};

//
// Execute `RUGclusters.R` in DeployR and pipe geoJSON response into CouchDB
//
deployr.script('/sheri/geo/RUGclusters.R')
    .numeric('nclus', 5)
    .pipe(JSONStream.parse('deployr.response.execution.artifacts.*.url'))
    .pipe(JSONStream.stringify(false))
    .pipe(geo);

mlds-couchdb-demo's People

Contributors

swells avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.