knitr::opts_chunk$set(echo = TRUE)
PranaGEO R API engine is a scalable, secure, stateless REST API alowing to make R calls. It is possible to run code that is offered by standart R or in 3rd party R packages that can be easily installed from CRAN, GitHub or similar sources.
HTML rendering of this document will be deployed online at http://coreos3.pranageo.com/ocpu/apps/pranageo/graphileonR/www/R_API_Examples.html
library(httr) library(jsonlite)
The input data for this demo is accessible (online)[https://github.com/PranaGeo/graphileonR/blob/master/inst/extdata/data.json]. One can download it directly with curl :
```{bash results="hide"} curl -O https://raw.githubusercontent.com/PranaGeo/graphileonR/master/inst/extdata/data.json
or use the getter function *grr_sampledata()*
```{bash results="hide"}
curl -X POST http://coreos3.pranageo.com/ocpu/apps/pranageo/graphileonR/R/grr_sampledata/print
We can also download it using R and convert it to data.frame
res <- POST("http://coreos3.pranageo.com/ocpu/apps/pranageo/graphileonR/R/grr_sampledata/print") df <- jsonlite::fromJSON(rawToChar(res$content)) df
To study the factors affecting the sleep, we could run a multiple linear regression on the dataset. The following analysis reveals how much the time spent at work/family/shopping is affecting the hours spent in sleep.
model <- lm(sleep ~ work + family + shopping, data = df) summary(model)
Using curl
curl -X POST -s http://coreos3.pranageo.com/ocpu/apps/pranageo/graphileonR/R/grr_meananalysis/print -F sampledata=@"data.json"
Using R
res <- POST("http://coreos3.pranageo.com/ocpu/apps/pranageo/graphileonR/R/grr_meananalysis/json", body = list(sampledata=upload_file("../extdata/data.json"))) data <- fromJSON(fromJSON(rawToChar(res$content))) df.avg <- data.frame(hobby=names(data), averages=sapply(data, function(x)x)) df.avg
suppressPackageStartupMessages(library(plotly)) plot_ly(data=df.avg, labels=~hobby, values=~averages, type = "pie")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.