Exposing Rscipt as API typically involves 3 steps:
- Installing rApache
- Configuring rApache
- Linux environment – ubuntu
- latest version of R – R- 3.1.0
apt-get install r-base-dev apache2-mpm-prefork apache2-prefork-dev
- Once rApache is installed, start the rApache server as below:
- Since we are installing for the first time let us test if the setup is installed properly. Do the below steps.
- Once you have done the above step, Now access the below pages:
- Before getting into expose R-script as API let us understand the rApache configuration.
Once the rApache is installed the folder structure of rApache would be as below:
- In apache2.conf file, we need to configure all the sites/r-scripts that we need to expose as api.. Below we have set a directory at path “/var/www/RProject“ in directory tags in apache2.conf file.
- Now place the below R-script (test.r) generating a random normal distribution in the RProject folder specified above,in the code belowGET$p is input parameter we pass from URL.
- The api is ready for testing.We can access the api using IP.XXX.XXX.XXX/RProject/test.r?q=10 And the results would be as below:
- Detailed documentation of Installation is found here
service apache2 start
sudo vim /etc/apache2/apache2.conf #Added the following: