Blog posts on Data Science, Machine Learning, Data Mining, Artificial Intelligence, Spark Machine Learning

Thursday, April 9, 2015

Exposing R-script as API

R is getting popular programming language in the area of Data Science. Integrating Rscript with web UI pages is a challenge which many application developers are facing. In this blog post I will explain how we can expose R script as an API, using rApache and Apache webserver.
rApache is a project supporting web application development using the R statistical language and environmentand the Apache web server.





Exposing Rscipt as API typically involves 3 steps:
  1. Pre-requisites
  2. Installing rApache
  3. Configuring rApache
Step #1 - Pre_requisites :
  • Linux environment - ubuntu
  • latest version of R - R- 3.1.0

Step#2 - Install apache webserver as below:
apt-get install r-base-dev apache2-mpm-prefork apache2-prefork-dev
wget http://www.rapache.net/rapache-1.2.3.tar.gz
 tarxzvf rapache-1.2.3.tar.gz
cd rapache-1.2.3
 ./configure
 make
make install
Step#3: Configuring rApache.
  • Once rApache is installed, start the rApache server as below:
  • service apache2 start
  • Since we are installing for the first time let us test if the setup is installed properly. Do the below steps.
  • sudo vim /etc/apache2/apache2.conf #Added the following:

  • Once you have done the above step, Now access the below pages:
  • IPAddress/html/index.html

    IPAddress/RApacheInfo.html

  • 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

22 comments:

  1. Something I wanted to try. Thank you, you don't believe how important it is. Make sure to check the link below:
    buy a logo

    ReplyDelete
  2. Hey there! I could have sworn I've been to this website before but after checking through some of the post I realized it's new to me. Anyways, I'm definitely glad I found it and I'll be book-marking and checking back frequently! best florist singapore

    ReplyDelete
  3. Hello there! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche. Your blog provided us beneficial information to work on. You have done a marvellous job! relex smile singapore

    ReplyDelete
  4. If you have begun noticing symptoms such as diminishing sex drive, fatigue, depression, mood swings, unexplained weight gain or hair loss, you do not have to simply accept these issues as a part of aging. Testosterone replacement therapy in men can put the spring back into your step and help you feel invigorated and confident once more.testosterone replacement therapy in men

    ReplyDelete
  5. I do agree with all the ideas you have presented in your post. They're really convincing and will definitely work. Still, the posts are very short for beginners. Could you please extend them a bit from next time? Thanks for the post.dragon tiger game

    ReplyDelete
  6. We just couldnt leave your site before saying that I genuinely enjoyed the quality information you provide to your visitors? Will be again soon to check up on new posts

    ReplyDelete
  7. Our article composing administration is intended to get you the get help with your assignment additional assist you with requiring in finishing your next college exposition. We match the best scholastic essayists, qualified across a gigantic scope of subjects and grades, to demands for help from understudies very much like you. Writing in wonderful english, our scholars will make a custom piece of work planned only for yourself and to assist you with arriving at the grade you require.

    ReplyDelete
  8. We figure the most effective way to feature the nature of our exposition composing administration is to show you our work - it represents itself with no issue! We've created a few phenomenal examples that show you precisely the sort of Write My Assignment Online For Me In UK work you'll get while requesting from us. Investigate our example expositions, ready at undergrad and expert's level across a scope of grades and subjects.

    ReplyDelete
  9. Rammafoundation is a foundation repair Edmonton company that specializes in all types of foundation repair, including corrective and preventative repairs. We are a family-owned and operated business that has been repairing foundations since 1976. We use the latest technology and equipment to do our job correctly, and we are always up to date on the latest industry trends. We also offer a free foundation survey so you can get a better idea of the damage your home's foundation may suffer. Contact us today to schedule a consultation, and let us help you get your home back on track!

    ReplyDelete
  10. Track down the entirety of your coat, coat, and outerwear needs this season at Urban Outfitters. Shop different styles including denim coats. Find the selective Men's creator Jackets and Coats assortment by VERSACE. Purchase online the notorious VERSACE items, extravagance and tastefulness models.

    ReplyDelete
  11. We know how to build strong foundationsCEMENT TREATED BASE for buildings and offices so do visit hastencontracting !!

    ReplyDelete
  12. The objective of this competition 404 tournament in Dubaiis to promote brands and swiftly increase brand recognition.

    ReplyDelete
  13. The transaction will go forward withoutTrade advisory services in Dubai a hitch because TACB has a lot of experience using a variety of financial instruments.

    ReplyDelete
  14. We have been providing chemical injectiochemical injection in UAEn solutions, pressure monitoring equipment, and fluid transfer pumps.

    ReplyDelete
  15. In order to develop software solutionsMobile app development dubai that will last the longest, the team at Arix Digital

    ReplyDelete
  16. Enjoy the exquisite flavour of JeddahBuy chocolate truffles Jeddah chocolate right now!

    ReplyDelete
  17. Indulge in the exquisite decadence of truffle in Jeddah, where fine chocolate and delicate flavors meld together in a harmonious blend. These luxurious treats offer a moment of pure indulgence, delighting chocolate enthusiasts with their rich, smooth centers.

    ReplyDelete
  18. Unlocking the power of R-scripts by exposing them as APIs. Just as Ceramic Coating Ottawa adds a protective layer to your car, this method safeguards your data processes! #DataScience #APIs #RScript #OttawaCeramicCoating

    ReplyDelete
  19. Exposing an R-script as an API is a powerful way to share data analysis and visualization with the world. Catering services Pecos Texas where innovation and data-driven decisions matter, consider catering services to fuel your team's creative efforts. Just as APIs open up new possibilities, quality catering can ensure your team stays well-fed and focused on making your data solutions a success. Keep exploring the data-driven future!

    ReplyDelete
  20. Exposing R-script as API is a tech-savvy move, unlocking the power of data analytics for seamless integration. As you delve into this dynamic process, ensure optimal ventilation for your spaces with a reliablekdk exhaust fan supplier in uae. Explore suppliers in the UAE for efficient air circulation, harmonizing technological innovation with essential comfort in your environment."

    ReplyDelete
  21. "Say goodbye to morning rushes with order coffee online in dubaiIndulge in the convenience of having your favorite brews delivered right to your door, ensuring a perfect start to your day. With a wide selection of blends to choose from, satisfaction is just a click away."

    ReplyDelete