Hey folks, nice to see that you are still with me for this Prevision.io R SDK blog post series! Since we have a deployed experiment that is fed with a pipeline, we may want to expose newly made predictions within a nice little WEB application.

Shiny application

Since you are an avid R coder, you probably already know what an R Shiny application is, but if not, here is a basic definition. As stated by the package writer (RStudio) : “Shiny is an R package that makes it easy to build interactive web apps straight from R. You can host standalone apps on a webpage or embed them in R Markdown documents or build dashboards. You can also extend your Shiny apps with CSS themes, html widgets, and JavaScript actions.”

 

To put it more simply, you can make WEB apps using Shiny and I strongly encourage you to do so. This blog post isn’t just about creating an R Shiny application, but also about actually deploying it. If you need more information about how to get started with Shiny, I recommend you read the following articles available on the RStudio website https://shiny.rstudio.com/tutorial/.

 

In order to simplify this tutorial, I have created a public github repository that contains a boilerplate Shiny application: https://github.com/previsionio/r-sdk-app. Feel free to use it raw or to adapt it to your need 😉

Prevision.io & Apps deployment

Just like deploying models coming from an experiment can be done with Prevision.io, apps follow almost the same route. To do it, you first need to develop the custom WEB application and then host your code into either github or gitlab.

 

As of today, Prevision.io supports 3 types of apps:

  • NodesJS apps for hardcore web developers
  • Dash apps for our python friends
  • Shiny apps, for us, R coders (feel free to use the above script!)

 

In order to deploy an app, you need to do it thanks to the UI. The idea is first to link your Prevision.io account with your github or gitlab account (might be already done if you tried to do a custom component 😊). If not, it will only take a couple of clicks.

 

All of this happens in your project in the Deployments > Deployments applications tab.

 

Make sure to be on the “deployments applications” tab

 

From here you can find the “Deploy new application” button:

Self explicit button

Here comes the serious configuration (nah, joking, it’s pretty easy 🙃). First, give your app a name. Make sure this is unique because we will generate a custom URL automatically for you which is based on it, just like we do in model deployment. Also, make sure that you select the correct programming language which is R here.

Explicit name with automatically generated custom URL

Then, make sure that you link your repository and your desired branch hosting the app code. Also, make sure that you have a file named app.R containing the app code at the root of your repository. This step is mandatory.

Selecting the master branch of my repository that contains my app on my gitlab account

By then, you’ll have to choose how many resources you want to allocate to your app (CPU & RAM). Obviously, it will greatly depend on your app requirements.

Resources selection, within an elegant and simple UI. For the provided code, you can increase RAM to ~ 2 Go and let others settings to default

As of today, we offer up to 4 CPUs & 8 Gb of RAM per instance. If you need more, feel free to reach us out and we will increase that for you!

Furthermore, Prevision.io also offers a replica of your hosting. That means if you select only 1 instance then you won’t have any replica. If you select 3, 3 instances with the given capacity will be created and hosted behind a load balancer (don’t worry, we take care of that for you too 😎). At the moment, you can have up to 10 replicas for high availability apps 🤯

The next step is optional, but is a real must-have for production ready applications. It’s about environment variables. Whether you connect to an external database that requires authentication or more simply if you need to use your master token within your application because you want to retrieve, for instance, a prediction hosted in a deployed experiment (you see what I mean, right? 😉).

Locate the “add a variable” text and click on it if you have environment variables

Example of environment variables added. If you work with the provided repository, make sure to fill your PIO_URL and PIO_TKN environment variables accordingly

Last, but not least, rights management! Just like deployed models coming from experiments (weather from AutoML or external models), we do offer 3 levels of rights for apps:

  • Public, which means that every one with the URL will be able to access the app without even needing to authenticate.
  • Instance collaborators, only registered users on the instance (ex : cloud.prevision.io) will be able to access the app after being authenticated.
  • Project collaborators, only users with sufficient permissions within the context of the project will be able to access the app after being authenticated.

If you follow this tutorial with the provided example, you should be able to see something like this:

 

View of the demo app if you deploy it. In solid blue the forecast, in dashed orange actuals

 

From my side, I have made a complete Shiny application that gathers some actual data coming from RTE’s API (which is the French company responsible for network equilibrium, more info, in French, here), that are plotted directly compared to the forecast, and that are done every day thanks to a pipeline and stored in a database (this is way more complex than the boiler plate, but it gives you example of what you can do).

 

The app is available @ https://electricity-forecast.cloud.prevision.io/

Example of the app for the 2nd of November 2021, forecasted on the 31st september 2021

We made it! We now have our application hosted in Prevision.io with a custom URL and available to the entire world! 😎

In the next blog post, which is the last one, we will discuss model life cycle management and then we will conclude this series.

Florian Laroumagne

About the author

Florian Laroumagne

Senior Data Scientist & Co-founder

Engineer in computer science and applied mathematics, Florian specialized in the field of Business Intelligence then Data Science. He is certified by ENSAE and obtained 2nd place in the Best Data Scientist of France competition in 2018. Florian is the co-founder of Prevision.io, a startup specializing in the automation of Machine Learning. He is now leading several applied predictive modeling projects for various clients.