如何安装部署Shiny-Server?

R Project

1 基础知识

2.1 R Markdown

2.1.1 R Markdown的简介

– R Markdown可以将分析数据转换为高质量的文档、报告、演示文稿和仪表板

2.1.2 R Markdown的特点

– R Markdown文档支持复制
– R Markdown支持文本和代码嵌套排版显示
– R Markdown支持多种语言(R、Python、SQL)
– R Markdown支持数十中静态和动态输出格式(HTML、PDF、MS Word、Beamer、HTML5幻灯片、Tufte风格讲义等)

2.2 Shiny

2.2.1 Shiny的简介

– Shiny是一个R包
– Shiny可以在R中构建交付式Web应用程序

2.2.2 Shiny的特点

– Shiny支持嵌入到R Markdown中
– Shiny支持构建仪表板
– Shiny支持CSS、htmlwidgets和JavaScript扩展

2.3 Shiny-Server的简介

Shiny-Server是Shiny的Web服务端实现

2 最佳实践

2.1 环境配置

2.1.1 系统环境配置

OS = CentOS 8.x x86_64
Host Name = rstudio.cmdschool.org
IP Address = 10.168.0.68

2.1.2 关闭SELinux

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

2.2 安装R

2.2.1 下载指定版本的安装包

export R_VERSION=4.1.2
curl -O https://cdn.rstudio.com/r/centos-8/pkgs/R-${R_VERSION}-1-1.x86_64.rpm

2.2.2 安装R包

yum install R-${R_VERSION}-1-1.x86_64.rpm

2.2.3 设置环境变量

export R_VERSION=4.1.2
ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R
ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript

设置完毕后,可使用如下命令确认设置,

R --version

2.3 安装shiny

R -e "install.packages('shiny', repos='https://cran.rstudio.com/')"

如果使用普通用户调用root则使用如下命令,

sudo su - \
-c "R -e \"install.packages('shiny', repos='https://cran.rstudio.com/')\""

安装完毕后,可以使用如下命令验证,

R -e 'packageVersion("shiny")'

另外,建议安装如下包,

R -e "install.packages('rmarkdown',repos='https://cran.rstudio.com/')"

2.4 安装shiny-server

2.4.1 安装软件包

wget https://download3.rstudio.org/centos7/x86_64/shiny-server-1.5.17.973-x86_64.rpm
yum install --nogpgcheck shiny-server-1.5.17.973-x86_64.rpm

另外,其他版本请从如下链接下载,
https://www.rstudio.com/products/shiny/download-server/
安装完毕后,可以使用如下命令查看倾听的端口,

netstat -antp | grep shiny-ser

可见如下显示,

tcp6       0      0 :::3838                 :::*                    LISTEN      79226/shiny-server

2.4.2 服务控制相关命令(可选)

systemctl start shiny-server.service
systemctl stop shiny-server.service
systemctl restart shiny-server.service
systemctl status shiny-server.service
systemctl disable shiny-server.service
systemctl enable shiny-server.service

2.4.3 开放防火墙端口

firewall-cmd --permanent --add-port 3838/tcp
firewall-cmd --reload
firewall-cmd --list-all

2.4.4 修改存储目录

mkdir -p /data/shiny-server
cp -r /opt/shiny-server/samples/* /data/shiny-server/
chown shiny:shiny -R /data/shiny-server
chmod 775 -R /data/shiny-server
vim /etc/shiny-server/shiny-server.conf

配置修改如下,

# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

# Define a server that listens on port 3838
server {
  listen 3838;

  # Define a location at the base URL
  location / {

    # Host the directory of Shiny Apps stored in this directory
    site_dir /data/shiny-server;

    # Log all Shiny output to files in this directory
    log_dir /var/log/shiny-server;

    # When a user visits the base URL rather than a particular application,
    # an index of the applications available in this directory will be shown.
    directory_index on;
  }
}

配置修改完毕后,需要重载使配置生效,

systemctl reload shiny-server.service

2.4.4 浏览器测试

http://10.168.0.68:3838/

参阅文档
============

RMarkdown简介
————
https://rmarkdown.rstudio.com/index.html

Shiny的简介
————–
https://shiny.rstudio.com/

Shiny-Server的简介
————–
https://github.com/rstudio/shiny-server
https://www.rstudio.com/products/shiny/shiny-server/

下载地址
————–
https://www.rstudio.com/products/shiny/download-server/
https://www.rstudio.com/products/shiny/download-server/redhat-centos/

没有评论

发表回复

R Project
如何安装配置RStudio Server?

1 基础知识 1.1 RStudio的介绍 RStudio是R编程语言集成开发环境(IDE) 1.2 …

R Project
如何管理R的软件包?

1 前言 R语言使用“base”与“utils”软件包实现管理,本章整理两个包的常用命令,以备使用。 …

R Project
如何编译安装R-Project?

1 基础知识 R语言(r-project)是主要用于统计分析、绘图的语言和操作环境。 2 最佳实践 …