TC7.31 - Create Data Analytic Flow


Warning message

You can't delete this newsletter because it has not been sent to all its subscribers.

Test Case Title

TC7.31 - Create Data Analytic Flow


You can learn how to Build your own script (in R) that performs statistical analysis and run it as a microservice on nodered/IOT Applications.
Possibility to make it public for all users of the platform.


  • Know the language R and have used R Studio
  • have an access to the R Studio integrated into the polatform or not, If you need one please follow the instruction reported on your development menu item
  • Know how to use the REST API for both data recovery (GET) and saving (POST)
  • Know how to use node-red to create streams that send data and show the responses received
  • Be a user of role at least at the role of AreaManager

Expected successful result

Realization of a flow inside node-red that can call at predefined intervals the script R created



You can decide whether to make the script R to upload to your R Studio or to our platform. To use RStudio on our platform you need to request credentials. To do so, you can go to the "Help & Contact" menu under "Contact Us, Problem Reporting".

Fill in the form by selecting the category you see in the picture asking in the message the credentials to access one of the available R Studios and indicating the subject as "RStudio Credentials".

Once you have obtained the credentials you can access the RStudio assigned through the menu that you see in the figure

On your R Studio you can develop the R script you wish to run with node-red:

The script created must contain a single function and must be noted at the beginning with the annotations provided by plumber (a library that allows you to transform the script R in a REST API).

In this example script, a GET Rest API is created (to retrieve information) and that responds to the url /trendCarPark. The next annotation indicates that the result returned by the script and then by the REST API is of type JSON (unboxed means that the JSON is not returned within an array). To see the possible output annotations click here.

The REST API created through this script will expect the variables passed as parameters to the function as call parameters. In this case it will expect traindDim and carParkName.

Once the script R has been created, it can be tested in your own IOT Application before it is made public to all users of the platform. If you don't know what an IoT Application is, see TC 2.1a. Create your own IoTApplication to create one on the cloud or TC 2.1b. Use snap4city nodes on your local IoT Application IotApplication to create one locally on your PC. In particular, if you create it on the cloud it must be an Advanced IoTApplication and if you create it locally you must install the node-red-contrib-snap4city-developer nodes. Once you have opened the IoT Application interface, you must insert this node into the stream you are creating to test the script.

By double-clicking on it, you can configure it. The configuration of the node of the example we are explaining can be seen in the following figure.


Enter all the data, making sure that all data are required and the relative uri must be the one inserted in the script R,  then you can press the button and create the REST API of the script.

If you are working on a local IoTApplication on your PC the configuration view is slightly different because you must also enter the username and password that allow you to create the REST API being not in the cloud


At the input the node thus created we add an inject node and at the output a debug node

The input node must be configured to send a JSON containing the parameters required by the function created in the Script R


If everything happened successfully and script R was written correctly by clicking on the button that sends the JSON to the node containing the script, you must see the script's response in the debug tab.