<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/opencpu-release-1-6/"></div></div><div><a data-url="http://www.r-bloggers.com/opencpu-release-1-6/" data-counturl="http://www.r-bloggers.com/opencpu-release-1-6/" data-count="horizontal" data-text="OpenCPU release 1.6" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.opencpu.org/posts/opencpu-1-6/"> OpenCPU</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p> <a target="_blank" href="https://www.opencpu.org/posts/opencpu-1-6"><img alt="opencpu logo" src="https://www.opencpu.org/images/stockplot.png"></a></p>
<p>Following a few weeks of testing, OpenCPU 1.6 has been released. OpenCPU is a production-ready system for embedded statistical computing with R. It provides a neat <a target="_blank" href="https://www.opencpu.org/api.html">API</a> for remotely calling R functions over HTTP via e.g. JSON or <a target="_blank" href="https://gist.github.com/jeroenooms/1984c784a6eff71f508f">Protocol Buffers</a>. The OpenCPU server implementation is stable and has been thorougly tested. It runs on all major Linux distributions and plays nicely with the RStudio server IDE (<a target="_blank" href="https://youtu.be/kAfVWxiZ-Cc?t=847">demo</a>).</p>
<p>Similarly to shiny, OpenCPU can run as a single-user development server within the interactive R session, and as a multi-user (cloud) server for deployments on Linux. Unlinke shiny however, the cloud server comes at no extra cost. On the contrary: you are encouraged to take advantage of the cloud server which is much faster and includes cool features like user libraries, concurrent sessions, continuous integration, customizable security policies, etc.</p>
<h3>Improvements: protolite and feather</h3>
<p>The OpenCPU API has not changed from the 1.4 and 1.5 branch. The version bump indicates that this version targets the R 3.3 and supports the new Ubuntu 16.04. Furthermore the underlying stack of bundled R packages has been upgraded. Navigate to <a target="_blank" href="https://public.opencpu.org/ocpu/info"><code>/ocpu/info</code></a> on your OpenCPU server to inspect the exact versions of all packages used by the system.</p>
<p>This version introduces two major improvements for binary data interchange. First the RProtoBuf dependency has been replaced by the much smaller <a target="_blank" href="https://cran.r-project.org/web/packages/protolite/index.html">protolite</a> package, which has an optimized version of protobuf object serialization. The OpenCPU already had an API for exporting data to Protocol Buffers, it’s just much faster now.</p>
<div>
<pre><code><span>library</span><span>(</span><span>httr</span><span>)</span>
<span>library</span><span>(</span><span>protolite</span><span>)</span>
<span>req</span> <span>&lt;-</span> <span>GET</span><span>(</span><span>&quot;https://demo.ocpu.io/ggplot2/data/diamonds/pb&quot;</span><span>)</span>
<span>mydiamonds</span> <span>&lt;-</span> <span>unserialize_pb</span><span>(</span><span>content</span><span>(</span><span>req</span><span>))</span>
</code></pre>
</div>
<p>New in this version is the <code>feather</code> output format which can be parsed/generated with the new <a target="_blank" href="https://cran.r-project.org/web/packages/feather/index.html">feather</a> package.</p>
<div>
<pre><code><span>library</span><span>(</span><span>curl</span><span>)</span>
<span>library</span><span>(</span><span>feather</span><span>)</span>
<span>curl_download</span><span>(</span><span>&quot;https://demo.ocpu.io/ggplot2/data/diamonds/feather&quot;</span><span>,</span> <span>&quot;diamonds.feather&quot;</span><span>)</span>
<span>mydiamonds</span> <span>&lt;-</span> <span>read_feather</span><span>(</span><span>&quot;diamonds.feather&quot;</span><span>)</span>
</code></pre>
</div>
<p>Both <code>pb</code> and <code>feather</code> are a binary alternative to the text based <code>json</code> format:</p>
<div>
<pre><code><span>library</span><span>(</span><span>curl</span><span>)</span>
<span>library</span><span>(</span><span>jsonlite</span><span>)</span>
<span>con</span> <span>&lt;-</span> <span>curl</span><span>(</span><span>&quot;https://demo.ocpu.io/ggplot2/data/diamonds/json&quot;</span><span>)</span>
<span>mydiamonds</span> <span>&lt;-</span> <span>fromJSON</span><span>(</span><span>con</span><span>)</span>
</code></pre>
</div>
<h3>Installation and upgrading</h3>
<p>The <a target="_blank" href="https://www.opencpu.org/download.html">download</a> page has instructions for installing the opencpu server on various distributions, either from source or using precompiled binaries. To upgrade an existing installation of opencpu on ubuntu, simply run:</p>
<figure>
<pre><code data-lang="bash">sudo add-apt-repository ppa:opencpu/opencpu-1.6
sudo apt-get update
sudo apt-get dist-upgrade</code></pre>
</figure>
<p>Note that this will also upgrade the version of R to 3.3.0 (if you have not already done so) which might require that you reinstall some of your R packages.</p>
<p>You can also install opencpu-server on any version of Debian/Ubuntu/Fedora/CentOS/RHEL by building the deb/rpm installation package from source. This is really easy, see the readme for <a target="_blank" href="https://github.com/jeroenooms/opencpu-server/tree/master/debian#readme">deb</a> or <a target="_blank" href="https://github.com/jeroenooms/opencpu-server/tree/master/rpm#readme">rpm</a>.</p>
<h3>Getting started</h3>
<p>For those completely new to OpenCPU there several resources to get started. The <a target="_blank" href="https://youtu.be/kAfVWxiZ-Cc">presentation</a> from last year’s useR conference gives a broad overview of the system including some basic demo’s. The <a target="_blank" href="https://www.opencpu.org/apps.html">example apps</a> and <a target="_blank" href="http://jsfiddle.net/user/opencpu/fiddles/">jsfiddle scripts</a> show how to use the <a target="_blank" href="https://www.opencpu.org/jslib.html">opencpu.js</a> JavaScript client. The <a target="_blank" href="http://jeroenooms.github.com/opencpu-manual/opencpu-server.pdf">server manual</a> has contains documentation on configuring your opencpu cloud server (although installation should work out of the box).</p>
<p>Finally this <a target="_blank" href="http://arxiv.org/abs/1406.4806">paper</a> from my thesis describes more generally the challenges of embedded scientific computing, and the benefits (both technical and human) of decoupling your statistical computing from your front-end or application layer.</p>
<h3>The public demo server</h3>
<p>To deploy your OpenCPU apps on the public server, simply push your R package to Github and configure the <a target="_blank" href="https://www.opencpu.org/api.html#api-ci">webhook</a> in your repository. Whenever you push an update to Github the package will be reinstalled on the server and can directly be used remotely by anyone on the internet. You can either use the full url or the <code>ocpu.io</code> shorthand url:</p>
<ul>
<li><code>https://public.opencpu.org/ocpu/github/{username}/{package}/</code></li>
<li><code>https://{username}.ocpu.io/{package}/</code></li>
</ul>
<p>These urls are fully equivalent. Simply replace <code><span>{</span><span>username</span><span>}</span></code> with your github username, and <code><span>{</span><span>package</span><span>}</span></code> with your package name. Note that the package name must be identical to the github repository name (as is usually the case).</p>
<h3>On writing packages</h3>
<p>One prerequisite for using OpenCPU is knowing how to create an R package. There is no way around this; packages are the natural container format for shipping and deploying code/data/manuals in R, and the OpenCPU API assumes this format. Luckily, writing R packages is super easy these days and can be done in less than (<a target="_blank" href="https://youtu.be/kAfVWxiZ-Cc?t=847">10 seconds</a>) using for example RStudio.</p>
<p>The good thing is that once you passed this little hurdle, the full power and flexibility of R and it’s packaging become available to your applications and APIs. Hadley’s latest <a target="_blank" href="http://r-pkgs.had.co.nz/">book</a> on writing R packages gives a nice overview of the R packaging system, and the OpenCPU API provides an easy HTTP interface to all of these features.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/opencpu-release-1-6/"></div></div><div><a data-url="http://www.r-bloggers.com/opencpu-release-1-6/" data-counturl="http://www.r-bloggers.com/opencpu-release-1-6/" data-count="vertical" data-text="OpenCPU release 1.6" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.opencpu.org/posts/opencpu-1-6/"> OpenCPU</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/AKscjk1X7M0"></a></div>