标签:
结合实际的工作环境,在开始R研究的时候,首先着手收集的就是能以Web方式发布R运行结果的基础框架,无耐的是,R一直以来常使用于个人电脑的客户端程序上,大家习惯性的下载R安装包,在自己的电脑上安装 --> 写算法 --> 运行 --> 以贴图或者文档的形式发表自己的作品。幸运的最终找着了一套这样的框架FastRWeb (Fast Interactive Web Framework for Data Mining Using R),参考 (http://www.rforge.net/FastRWeb/),FastRWeb 是一个基础架构环境, 可以让R脚本运行在任何WebServer上,展示数据和图形,用户通过URL地址与R脚本进行通信交互。
目录:
运行架构原理:
Centos7 R3.2.5软件包安装:
yum install -y gcc
yum install -y gcc-c++
yum install -y gcc-gfortran
yum install -y readline-devel
yum install -y libXt-devel
yum install –y libcur*
yum install –y libxml*
yum install –y openssl*
将下载到本机的R安装包软件上传文件至linux主机的某目录下, 执行解压命令:tar -zxvf R-3.2.5.tar.gz
R is now configured for x86_64-pc-linux-gnu Source directory: . Installation directory: /home/work/R C compiler: gcc -std=gnu99 -g -O2 Fortran 77 compiler: gfortran -g -O2 C++ compiler: g++ -g -O2 C++ 11 compiler: g++ -std=c++11 -g -O2 Fortran 90/95 compiler: gfortran -g -O2 Obj-C compiler: Interfaces supported: X11 External libraries: readline Additional 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: yes configure: WARNING: you cannot build info or HTML versions of the R manuals configure: WARNING: you cannot build PDF versions of the R manuals configure: WARNING: you cannot build PDF versions of vignettes and help pages [root@R R-3.2.5]#
PATH=/home/work/R/bin:$PATH
RStudio 安装配置:
systemctl status rstudio-server
systemctl start rstudio-server
systemctl stop rstudio-server
systemctl restart rstudio-server
执行下面的命令清单,给RStudio添加操作用户和权限
adduser rstudio
passwd rstudio
usermod -g rstudio-server rstudio
命令:systemctl start rstudio-server (启动rstudio-server 服务,默认监听端口 8787)
FastRWeb安装:
g++ Rconnection.o Rcgi.o -o Rcgi -lcrypt make[1]: Leaving directory `/tmp/RtmpdpC13f/R.INSTALL53b568210efe/FastRWeb/src/Rcgi‘ rm -rf ../inst/Rcgi cp -r Rcgi ../inst mkdir ../inst/cgi-bin touch null.so null.dll # to make R CMD SHLIB happy installing 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 installed package can be loaded * DONE (FastRWeb) The downloaded source packages are in ‘/tmp/RtmpkNJBem/downloaded_packages’ Updating HTML index of packages in ‘.Library‘ Making ‘packages.html‘ ... done >
R命令:install.packages("Rserve")
./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 for lazy loading ** help *** installing help indices ** building package indices ** testing if installed package can be loaded * DONE (Rserve) The downloaded source packages are in ‘/tmp/RtmpkNJBem/downloaded_packages’ Updating HTML index of packages in ‘.Library‘ Making ‘packages.html‘ ... done >
R命令: q() (退出R命令行,返回linux命令行)
http.port 8888 remote enable source /var/FastRWeb/code/rserve.R control enable
修改文件:rserve.R, 在文件上的最上面增加2行代码,如下
library(FastRWeb)
.http.request <- FastRWeb:::.http.request
命令: ./start (开启服务,注意:必须切换至 /var/FastRWeb/code 目录下执行)
开发Demo: hello world
run <- function(...){ oprint("hello world") done() }
如果是本地环境开发的,将保存的Demo.R 文件上传至 /var/FastRWeb/web.R 目录下
标签:
原文地址:http://www.cnblogs.com/tgzhu/p/5770090.html