Giter Club home page Giter Club logo

opencpu.js's Introduction

Javascript library for OpenCPU

opencpu.js is a Javascript client library for OpenCPU (www.opencpu.org). It is a foundation for developing OpenCPU apps: R packages containing a web application that calling R functions though the OpenCPU API.

A note about hotlinking

It is better not to hotlink the javascript library straight from github. The library is under active development and the latest version on Github changes rigorously from time to time. If you build apps, please include a copy of jQuery and opencpu.js in the package. For cross domain applications, you can use:

<script src="//code.jquery.com/jquery-1.10.2.min.js"></script> 
<script src="//www.opencpu.org/js/archive/opencpu-0.4.js"></script>

This file will not have any breaking changes. Also note that by not specifying http or https, the browser will automatically use the same protocol as is used to host the webpage, which prevents "mixed content" security problems.

Documentation

The documentation for this library is now available on the OpenCPU website: https://www.opencpu.org/jslib.html

Apps

Example apps that use opencpu.js can be found on the OpenCPU website: https://www.opencpu.org/apps.html

opencpu.js's People

Contributors

jeroen avatar psolymos avatar

Stargazers

 avatar Matheus Rech avatar bhoga avatar  avatar  avatar  avatar benben-miao avatar Superquant avatar Muhibbudin Suretno avatar ShadowBoxingSkills avatar Fabian Morón Zirfas avatar Jan Küster avatar Billy Raseman avatar Hatem Hosny avatar  avatar Nico avatar Daniel Guo avatar Satoru "Con" Takasimizu avatar Mikal avatar Rodrigo Carneiro avatar Andrew Starodubtsev avatar Leensey L. avatar Yudha Ha Te avatar  avatar Amanda Shih avatar Derek avatar SINCERE INDIE WEB LABEL  avatar Philipp Burckhardt avatar Xeronith avatar Jean Carlo Nascimento avatar Emmanuel Blondel avatar Angus H. avatar Nikhil Gopal avatar Laurentiu Amagdei avatar Matt Bannert avatar Vieko Franetovic avatar Gavin Wong avatar Michael Anthony avatar Athan avatar Cristian Martinez avatar Bertjan Broeksema avatar Gergely Daróczi avatar Kun Ren avatar Carson Sievert avatar Richard Griffith avatar Ben West avatar Stu Thompson avatar Richard M. Smith avatar Martinez-Lopez Javier avatar Erik Iverson avatar  avatar James Chang avatar Wang avatar Zhiping Yang avatar Jay B. Martin avatar  avatar

Watchers

Yudha Ha Te avatar  avatar Richard Hulek avatar James Cloos avatar Michael Anthony avatar James Chang avatar  avatar Reto Wyss avatar SINCERE INDIE WEB LABEL  avatar

opencpu.js's Issues

Add option to throw exceptions on errors

I'm using OpenCPU to incorporate R code into an existing application, and it needs to be able to handle OpenCPU errors internally instead of having them generate alerts or log to the console. For instance, when seturl() fails, it uses alert() to raise a dialog box. And as the connection is made, messages are logged with console.log().
When getting started, and in pages, the way opencpu.js uses alert() and console.log() is very helpful, so I still think that should be the default behavior. Would it be appropriate to create a flags on the ocpu object that tells it whether to use alert() or throw exceptions, and whether to log debug messages?
If this would be acceptable, I can submit a pull request.

detect CORS problems

Add a failure handler for

  $.get(r_path.href, function(resdata){
    console.log("Path updated. Available objects/functions:\n" + resdata);
  });

To detect problems due to CORS/HTTPS (e.g. mixed content problems)

How to use `ocpu.r_fun_call`?

Hello,
I am able to use the ocpu.rpc function, but not the ocpu.r_fun_call function. According to my understanding of the documentation, the following code should work, but it does not (nothing happens when I click on the submit button).

<html>
  <head>

    <script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="//cdn.opencpu.org/opencpu-0.5.js"></script>

    <script>

    $(document).ready(function(){

        $("#submitbutton").click(function(){
          var req = ocpu.r_fun_call("mean", {"x" : 10}, function(session){
            session.getObject(function(data){
              $("#namefield").val(data);
            });
          });
        });

    });

    </script>

  </head>

  <body>

    <input type="text" id="namefield" value="">

    <button id="submitbutton" type="button">Submit!</button>

  </body>
</html>

Add to Bower

It would be nice to be able to pull this into a project via Bower the standard way (though it can still be done via URL).

opencpu Internet explorer 8 not working

Hi

I still not able to make opencpu working from internet explorer 8.
The app demo pages gives me a Github API Error Could not load apps list from repository. Might be a problem with github. Have a look at status.github.com and try againt later

In the meantime my own applications crashes with this error Could not find jQuery! The HTML must include jquery.js before opencpu.js. However this works perfectly on firefox & google chrome.

Am I the only user having trouble with openCPU ? (I know a previous issue existed on that topic opencpu/opencpu#169)

Thanks

Issue with jqxhr location returned as http when opencpu deployed in a secured infra

Dear @jeroen

I write to seek for your advice on dealing on a case where we have deployed an OpenCPU in a corporate infrastructure, where the https ssl certificates are managed upstream and not at opencpu server level.

As consequence, we get a mix-origin security issue when using the opencpu.js since the Location response header we get from jqxhr at https://github.com/opencpu/opencpu.js/blob/gh-pages/opencpu-0.5.js#L154 where the location is returned as http although the server is in https.

As hard (dirty) fix, the only solution to make it work was to do jqxhr.getResponseHeader('Location').replace('http://', 'https://') forcing the response header location to be in https.
I'm wondering if there would be a better solution to that, hopefully captured directly in your code.

Thanks in advance
Emmanuel

Unexpected token :

Hello,
I'm getting an "Unexpected token :" error for opencpu-0.5.js line 148. I think
settings.xhrFields: {
should instead be
settings.xhrFields = {
Thanks,
Thomas

More specific error messages

The stockapp currently says "failed to plot stock" when the server is down. Should distinguish http 400 errors from 50x or connection failure.

Bug

Someone on SO says:

Finally I made it work but I had to comment this line in opencpu-0.4.js, in r_fun_ajax function: //in case of cors we translate the relative path if(r_cors){ //loc = r_path.protocol + "//" + r_path.host + loc; } Loc variable already contained full path, host and location, and in this line path was added again, returning a wrong location. Commenting that line I got the right location and my example started to work fine.

OpenCPU clients for R/Stata?

Probably not the right place to ask, but was wondering if you've come across standard R (and possibly STATA) clients for OpenCPU APIs? Also wondering if I should just write a wrapper for opencpu.js (e.g. using V8/jsonlite in R), or better not to include a dependency on the .JS libs?
Thanks!

Add a license

Could you please add a licence file to make clear under what conditions OpenCPU js can be used?

Retina support

Use window.devicePixelRatio or similar to request high resolution images.

You can do this by doubling the resolution passing an (undocumented?) parameter res to png. See rstudio example.

Calling from a Web Worker

Hi!

I'm using web workers for multi-threaded way of analyzing my data on the browser and I need to do some statistical tests with calls using OpenCPU. However, my first attempts to import it to a web worker didn't work. Since, there is no window or document object in a web worker, I tried to set them to self but jQuery complains about the document object.

// worker.js
var window = self,
    document = self;
importScripts('libs/jquery-1.11.3.js', 'libs/opencpu-0.4.js');
ocpu.seturl("//public.opencpu.org/ocpu/library/base/R");
Uncaught TypeError: Cannot read property 'createElement' of undefined jquery-1.11.3.js:930

Seeing that there are no JS libraries with such tests as in R, I think OpenCPU is the only way to do statistical computation on a browser.

This is actually a jQuery error but I just wanted to bring it to your attention. Any help about calling R code from the worker threads will be appreciated.

Thanks

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.