Example RServe Flow

Introduction

This flow contains a basic example on how to use node-red-contrib-R-nodes to do statistical data analysis using R in node-RED.

The given example simulates some input data and calculates the median as well as the mean of the given data using R.

Requirements

In order of this flow to work, it is required to run a R server. This can be accomplished by running the Rserve command within a R instance. For the communication between R and nodeRED it is also required to have the library RJSONIO installed.

R-Code to start Rserve

# Rserve package and RJSONIO needs to be installed
# install.packages("Rserve")
# install.packages("RJSONIO")

library(Rserve)
Rserve(args="--no-save")
[{"id":"acba6ff9.cbc76","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"580cb2a.906064c","type":"inject","z":"acba6ff9.cbc76","name":"Demodata input","topic":"","payload":"{\"data\":[0.48,-5.21,-0.21,7.81,10.43,13.81,16.24,15.89,12.56,8.04,2.79,-0.11,-2.39,6.01,15.31,7.8,0.21,12.79,6.88]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":140,"wires":[["a15cf396.5b792"]]},{"id":"a15cf396.5b792","type":"R Script","z":"acba6ff9.cbc76","RServer":"9cfb83f.b316c8","script":"msg$payload$mean = mean(msg$payload$data)\nmsg$payload$median = median(msg$payload$data)","name":"Calculate mean and median using R","x":390,"y":140,"wires":[["3b04d31c.d377dc"]]},{"id":"3b04d31c.d377dc","type":"debug","z":"acba6ff9.cbc76","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":140,"wires":[]},{"id":"9ce7ac17.dfc6","type":"comment","z":"acba6ff9.cbc76","name":"Requirement: RServe","info":"In order of this flow to work, it is required to run a R server. This can be\naccomplished by running the `Rserve` command within a R instance. For the\ncommunication between R and nodeRED it is also required to have the library\n`RJSONIO` installed.\n\n## R-Code to start `Rserve`\n\n```\n# Rserve package and RJSONIO needs to be installed\n# install.packages(\"Rserve\")\n# install.packages(\"RJSONIO\")\n\nlibrary(Rserve)\nRserve(args=\"--no-save\")\n```","x":120,"y":40,"wires":[]},{"id":"9cfb83f.b316c8","type":"R Server","z":"","host":"127.0.0.1","port":"6311","name":"local R Server"}]

Flow Info

Created 5 years, 3 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • comment (x1)
  • debug (x1)
  • inject (x1)
Other
  • R Script (x1)
  • R Server (x1)
  • tab (x1)

Tags

  • R
  • statistics
  • Rlang
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option