R (ii): HTTP and R script Communication environment installation

Source: Internet
Author: User
Tags cairo gfortran

The actual work environment, at the beginning of R Research, the first collection is to be able to publish the results of R Web-based framework, non-resistance, R has always been used for personal computers on the client program, everyone habitually download the R installation package, installed on their own computer on the write algorithm-- >--Publish your work as a decal or as a document. Fortunately, we finally found a set of such frameworks Fastrweb (Fast Interactive Web framework for Data Mining Using R), reference (http://www.rforge.net/FastRWeb/ ), Fastrweb is an infrastructure environment that allows R scripts to run on any webserver, displaying data and graphics, and communicating interactions with R scripts by the user via URL addresses.

Directory:

    • Operating Architecture Principles
    • R3.2.5 installation (CENTOS7)
    • Rstudio installation Configuration (CENTOS7)
    • Fastrweb installation Configuration (CENTOS7)
    • Development Demo:hello World

Operating Architecture principle:

    1. Clinet sending an HTTP request to the host's Rserve service
    2. Rserve invoke Fastrweb Environment, execute R script
    3. Returns the execution result
    4. In the actual work, inevitably encountered a situation, R script execution results are stored on the host's physical disk, in order for the client to access the generated file through HTTP, you can store the file in the HTTPD service corresponding to the HTML directory, R returned to the client may be the file name, After the client obtains the file name returned by R, it initiates the HTTP request again, accessing the files stored in the HTTPD Service site.
    5. Note: In this scenario,the two requests initiated by the client are actually different services that call the host (that is, the Rserve service and the httpd service, so be aware of the listening ports of the different services in the request)

CENTOS7 R3.2.5 Package Installation:

  • CentOS System software package (https://cran.r-project.org/src/base/R-3/), as of now, the latest version 3.3.1, the version we chose to install is: 3.2.5
  • To install the R software dependent package, the command list is as follows:
    Yum install-y gccyum install-y gcc-c++yum install-y gcc-gfortranyum install-y readline-develyum install-y libXt-devel Yum install–y libcur*yum install–y libxml*yum install–y openssl*
  • Download to the native R installation package software to upload files to a directory on the Linux host, performing the decompression command:tar-zxvf r-3.2.5.tar.gz

  • Command:CD R-3.2.5 (switch to the extracted directory)
  • Command:mkdir-p/home/work/r
  • Command:./configure--prefix=/home/work/r--enable-r-shlib (working directory setting R)
  • After completing the configuration, the interface is displayed as shown below, OK
    R is now configured forx86_64-pc-linux-GNU Source Directory:          .installation directory:/home/work/R C Compiler: Gcc-std=gnu99-g-O2 Fortran theCOMPILER:GFORTRAN-G-O2 C+ + compiler:g++-G-O2 C++ Onecompiler:g++-std=c++ One-G-O2 Fortran -/ theCOMPILER:GFORTRAN-G-O2 OBJ-C Compiler:Interfaces Supported:X11 External Libraries:ReadLineAdditional Capabilities:NLS Options enabled: Shared R Library, shared BLAS,R profiling capabilities skipped: PNG, JPEG, TIFF, Cairo,ICU Options not enabled:Memory profiling Recommended Packages:yesconfigure: WARNING:You cannot build info or HTML versions of the R manualsconfigure: WARNING:You cannot build PDF versions of the R manualsconfigure: WARNING:You cannot build PDF versions of vignettes and help Pages[root@RR3.2.5]#
  • Start compiling the installation
  • Command: make
  • Command: Makeinstall
  • Command:vim ~/.bash_profile (Configure environment variables, add the following line of code to the open file, where the R path is the –prefix=/home/work/r at the top of the installation)
    Path=/home/work/r/bin: $PATH
  • Command:source ~/.bash_profile (make changes effective)
  • Execute after completion: R (can enter the R command line normally, OK, such as)

RStudio Installation configuration:

  • Rstudio is a very useful R language IDE, its server-side software, can be built on a Linux server, and then through the remote Web site access, so that the use of R language has been greatly facilitated, but also as a small cloud service, the official website (https:// www.rstudio.com/home/), such as: Rstudio Server offers free and commercially licensed versions
  • Download the Software installation package (rstudio-server-rhel-0.99.903-x86_64.rpm) for the CentOS system and upload it to the host
  • Command: yum install--nogpgcheck rstudio-server-rhel-0.99.903-x86_64.rpm (software Installation)
  • Command: Echo ' rsession-which-r=/home/work/r/bin/r ' >>/etc/rstudio/rserver.conf (with context see this parameter configuration)
  • The list of reference commands for the RStudio service is as follows ( for reference only, not to be performed in this step ):
    Systemctl status Rstudio-serversystemctl start rstudio-serversystemctl stop rstudio-serversystemctl restart Rstudio-server
  • Execute the following list of commands to add action users and permissions to Rstudio

    AddUser rstudiopasswd rstudiousermod-g rstudio-server Rstudio
  • Command:systemctl start Rstudio-server (Start rstudio-server service, default listener port 8787)

  • If all is OK, the browser can be accessed normally, as follows:

Fastrweb Installation:

    • Fastrweb can quickly build an R Web environment, Fastrweb relies on CGI programs, which means that, as long as you can support the webserver of CGI programs, you can run Fastrweb
    • Command: yum install-y cairo-devel (Install Fastrweb dependent package Cairo)
    • Command:R (enter the R command line, both the Fastrweb and Rserve installation packages are installed online under the R command line)
  • R command: install.packages ("Fastrweb") (in this process select Install image, CENTOS7 environment, select HTTP mirrors, http cran mirrors Select 21 (China Xiamen))
  • After successful installation, such as:
    g++ RCONNECTION.O Rcgi.o-o rcgi-Lcrypt make[1]: Leaving directory '/tmp/rtmpdpc13f/r.install53b568210efe/fastrweb/src/rcgi'RM-RF. /inst/rcgicp-r rcgi. /instmkdir.  /inst/cgi-bintouch null.so Null.dll # to make R CMD shlib happyinstalling to/home/work/r/lib64/r/library/fastrweb/libs** r** inst** Preparing package for lazy loading** help*** Installing help indices** Building Package indices** Testing if I Nstalled package can is loaded* done (fastrweb) the downloaded source packages is in '/tmp/rtmpknjbem/downloaded_packag Es ' Updating HTML index of packages in'. Library'Making'Packages.html'. .. done>
  • R command:install.packages ("Rserve")

  • After the installation successful interface such as:
    ./mergefat Rserve"/home/work/r/lib64/r/bin/rserve"./mergefat rserve.dbg"/home/work/r/lib64/r/bin/rserve.dbg"Installing via'INSTALL.LIBS.R'to/home/work/r/lib64/r/library/Rserve**R**Inst* * Preparing Package  forLazy Loading** Help***Installing Help Indices* * Building PackageIndices* * TestingifInstalled Packagecan be loaded*Done (Rserve) The downloaded source packages is in '/tmp/rtmpknjbem/downloaded_packages ' Updating HTMLIndexof packages in'. Library'Making'packages.html'... Done>
  • R command: Q () (exit the R command line and return to the Linux command line)

    • Create a Fastrweb Rserve-based environment (switch to the Fastrweb installation directory, check the installed directory first, and then switch to that directory)
    • Command: Find/-name fastrweb (check fastrweb installation directory, e.g.)
    • Command:cd/home/work/r/lib64/r/library/fastrweb (switch to installation directory)
    • Command :./install.sh (Install Rserve-based runtime environment, generate/var/fastrweb directory)
    • Command:cd/var/fastrweb/code
    • Command:ls-la (view file contents)
      1. rserve.conf: Rserve Start-up parameters
      2. Rserve. R: Rserve's startup script
      3. Start : Start command
  • Command:vim rserve.conf (by default, Rserve is to provide the socket communication interface, we want to change it to HTTP communication interface, the code is as follows)
    Http.port 8888 remote Enable/var/fastrweb/code/Rserve. Rcontrol Enable
  • Modified file: Rserve. R, add 2 lines of code to the top of the file, as follows

    Library (fastrweb). Http.request <-Fastrweb:::.http.request
  • Command: ./start (Start service, note: must switch to/var/fastrweb/code directory to execute)

  • Service status can be viewed through ps-aux|grep rserve and netstat-nltp|grep rserve .
  • To stop the service, execute the command through the kill process, such as the process number: kill-9 53652
  • After the installation is complete, the browser will be able to access the OK, the default listener port 8888 (http://192.168.0.103:8888/info), such as

Development Demo:hello World

    • In the Rstudio IDE, write the following code save, named DEMO.R, you can use the local Windows environment of the Rstudio IDE, you can also use the IDE environment on the browser
      Run <- function (...) {    Oprint ("helloWorld") Done  ()}
    • If the local environment is developed, upload the saved DEMO.R file to/var/fastrweb/web. Under R directory

    • Execute in Browser: Http://192.168.0.103:8888/Demo, result is OK

R (ii): HTTP and R script Communication environment installation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.