Full Workspace Automation through a Programmatic Interface (API) Available Now

[This article was first published on Quantargo Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Full Workspace Automation through a Programmatic Interface (API) Available Now

Each workspace already is an API

QBit Workspace is a new service to immediately deploy data science results at scale. You can think of it as an online data science editor (like RStudio) which can also be controlled and automated from any programming language through a REST API. Once a workspace has been created—including code, environment objects and files—there is no need for a separate (API) deployment step any more. Each workspace already is an API. With its powerful REST API interface it can be easily embedded into any application, app or programming language without running and managing your own R- or Python server.

We’re now happy to announce the launch of our API service in public beta, which allows to control every aspect of the workspace programmatically including actions like:

  • Workspace creation
  • Workspace deployment
  • Code execution
  • Rendering of RMarkdown documents
  • File up- and downloads
  • Package install/remove

The API thus allows to create completely new use cases which can be easily embedded with any programming language into web applications or mobile apps. No API packages like R plumber or Python Flask are needed!

Get Started with the QBit Workspaces API

To use the API from R first install the qbit package from the Quantargo Github repository:


Next, you need to retrieve your free API key from the Quantargo page settings section:

For more information about API key creation and usage also see our detailed step-by-step guide. Ideally, set your API key QKEY through the options() settings as

options(QKEY = "")

so that all further API calls use the key accordingly. Now you are ready to interact with QBit workspace! As a first example, we’ll show how to create an API-ready RMarkdown report within R.

Creating RMarkdown Documents through the qbit R-API

RMarkdown combines markdown text with R outputs (e.g. plots, tables) to create reproducible documents in multiple output formats (e.g. HTML, PDF, Word, Powerpoint, see also here). Most R-data scientists use their local (RStudio) environment to produce these reports. But what if we want to render these reports through a web application on the fly, maybe even parametrized or with updated input data sets? In the following section we’ll create a QBit workspace for RMarkdown to quickly render an HTML document through the API.

Let’s start by creating a new workspace based on the RMarkdown template:

qbit_id <- qbit::create(qbit_name = "RMarkdown Example HTML document")
[1] "qbit-rmarkdown-example-html-document-eGJWV404T"

The created workspace received a new and unique qbit_id based on its qbit_name title. You can also visit the new workspace online and even share its link with your friends/co-workers. Further changes to your workspace can now be done through the API using the qbit::deploy() function or directly within the online editor.

Once you are satisfied with your workspace you can run specific R commands, retrieve their respective outputs and integrate them into your application. Most typically, you might want to execute specific commands like predict() (for model predictions) or any kinds of user–defined functions through qbit::run. The qbit::run interface, which allows to execute any arbitrary R code, is therefore very general and can support any complex API use cases. For our RMarkdown use case we would like to render the main.Rmd file as an HTML document with qbit::render:

render_out <- qbit::render(qbit_id)

The $console_output element contains a data frame (tibble) of all created contents through the call:

# A tibble: 8 x 3
  type       content                                          name   
  <chr>      <chr>                                            <chr>  
1 code-input "rmarkdown::render(\"main.Rmd\")"                   
2 code-mess… "Warning message: \n\nprocessing file: main.Rmd…    
3 code-outp… "\r  |                                         …    
4 code-outp… "\r  |                                         …    
5 code-mess… "Warning message: output file: main.knit.md\n\n"    
6 code-outp… "/usr/bin/pandoc +RTS -K512m -RTS main.utf8.md …    
7 code-mess… "Warning message: \nOutput created: main.html\n"    
8 file       "https://cdn.quantargo.com/assets/user/courses/… main.h…

The link of the created Rmarkdown document is located in the row where content type equals "file":

render_out$console_output %>%
  filter(type == "file")
# A tibble: 1 x 3
  type  content                                              name    
  <chr> <chr>                                                <chr>   
1 file  https://cdn.quantargo.com/assets/user/courses/b8451… main.ht…

The included link in the content column can be easily integrated into your own web application (via an <iframe> tag) or just downloaded locally (e.g. via download.file() in R).

Thanks to the serverless (AWS Lambda) back-end the QBit Workspace is quickly scalable to thousands of concurrent requests. The service is now available in public beta and can be deployed into your own infrastructure (Docker/Container based including Lambda, Kubernetes, Open Shift) upon request.

Happy deploying!

To leave a comment for the author, please follow the link and comment on their blog: Quantargo Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)