Вопрос

Is it possible to use opencpu.js with my own install of OpenCPU on Ubuntu? I've done a quick scan of the code and can't see where i would set the host name.

Это было полезно?

Решение

Edit: This feature has been improved in opencpu.js 0.3. You can now set the path of the opencpu server using `opencpu.seturl(). The argument must point to a package, for example:

opencpu.seturl("/ocpu/library/mypackage/R")

or if your browser supports CORS you can do:

opencpu.seturl("//public.opencpu.org/ocpu/library/mypackage/R")

or

opencpu.seturl("//public.opencpu.org/ocpu/github/yourname/yourpackage/R")

After setting this, the client will check if this server is online and print some debugging stuff to the javascript console. If all is OK, you can use the library just as if it were part of the app. Have a look at http://www.stat.ucla.edu/~jeroen/appdemo/ to see this in action.

That said, the opencpu.js library is designed to be included in apps. An OpenCPU app is an R package which includes some web page(s) that call the R functions in the package using the OpenCPU API.

Because apps are R packages which are installed on the OpenCPU server, the opencpu.js library assumes the server is running on the current host, and uses a relative path to call the server. Moreover, because opencpu.js is included with a particular R package, the functions in opencpu.js have no argument as to specify a package either: it assumes you are calling the R function the current package.

This might sound a little confusing at first, but relative paths are important to keep the application portable. For example, the same app should work regardless of whether it is hosted as:

https://public.opencpu.org/ocpu/gitstats/www
https://public.opencpu.org/ocpu/github/SChamberlain/gitstats/www/
https://public.opencpu.org/ocpu/user/jeroen/library/gitstats/www/

The big advantage of this design is that your R package will be a self-contained, standalone application, which can be deployed anywhere simply by installing the package. This prevents a lot of trouble with cross-domain requests and software versioning. Because your web pages and R functions are part of one and the same package, you can make sure the js and R code contain compatible versions. If you would be hosting the js on a separate server, than things might break when a new version of the R package is installed.

Perhaps the best way to get started is by having a look at one of the public apps. The source code for these apps is available on the opencpu github repo, and each app is built on the opencpu.js library.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top