Shiny server 可以在线发布shiny应用程序并让用户可以在线管理自己的shiny应用程序。
Shiny Server运行各种不同的shiny程序,
Shiny Server can manage R processes running various Shiny applications over different URLs and ports. Using Shiny Server offers a variety of benefits over simply running Shiny in R directly. These features allow the administrator to:
详细的shiny-server教程可以查看 https://docs.rstudio.com/shiny-server/
# install R
sudo apt-get install r-base
# install shiny
sudo su - \
-c "R -e \"install.packages('shiny', repos='https://cran.rstudio.com/')\""
# download and install
sudo apt-get install gdebi-core
wget https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-1.5.17.973-amd64.deb
sudo gdebi shiny-server-1.5.17.973-amd64.deb
# install R
sudo yum install R
# install shiny
sudo su - \
-c "R -e \"install.packages('shiny', repos='https://cran.rstudio.com/')\""
# download
wget https://download3.rstudio.org/centos7/x86_64/shiny-server-1.5.17.973-x86_64.rpm
# install
sudo yum install --nogpgcheck shiny-server-1.5.17.973-x86_64.rpm
详细可以查看https://www.rstudio.com/products/shiny/download-server/redhat-centos/
# 启动 shiny-server
sudo systemctl start shiny-server
# 停止 shiny-server
sudo systemctl stop shiny-server
# 重启 shiny-server
sudo systemctl restart shiny-server
# 检查 shiny-server 的状态
sudo systemctl status shiny-server
# 启动 shiny-server
sudo systemctl enable shiny-server
# 停止运行 shiny-server
sudo systemctl disable shiny-server
实际上来说,shiny-server的管理都在其配置文件上,默认情况下,它的配置文件是在/etc/shiny-server/shiny-server.conf
. 一般的shiny-server的配置文件内容如下:
# Define the user we should use when spawning R Shiny processes
# 设置运行R shiny 进程的user是谁
run_as shiny;
# Define a top-level server which will listen on a port
# 定义服务器的监听端口
server {
# Instruct this server to listen on port 3838
# shiny-server的监听端口为3838
listen 3838;
# Define the location available at the base URL
# 定义可以使用的基本URL链接
location / {
#### PRO ONLY ####
# Only up tp 20 connections per Shiny process and at most 3 Shiny processes
# per application. Proactively spawn a new process when our processes reach
# 90% capacity.
# 此处的设置是指可以同时有20个连接进行shiny的运行进程,最多每个应用程序有3个连接进程可以同时进行。
# 进程最多达到的90%的内存。
utilization_scheduler 20 .9 3;
#### END PRO ONLY ####
# Run this location in 'site_dir' mode, which hosts the entire directory
# tree at '/srv/shiny-server'
# 使用'site_dir'的话,对应的主目录是/srv/shiny-server
# 把应用程序放置在这个指定的目录下,即可运行。(记得提前安装好需要的R包)
site_dir /srv/shiny-server;
# Define where we should put the log files for this location
# 指定日志存放的位置在/var/log/shiny-server
log_dir /var/log/shiny-server;
# Should we list the contents of a (non-Shiny-App) directory when the user
# visits the corresponding URL?
# 当用户访问相关的URL链接时,是否显示当前目录下的内容
directory_index on;
}
}
# Setup a flat-file authentication system. {.pro}
# 设置平面文件身份验证系统,只有pro的shiny-server才可以运行。
auth_passwd_file /etc/shiny-server/passwd;
# Define a default admin interface to be run on port 4151. {.pro}
admin 4151 {
# Only permit the user named `admin` to access the admin interface.
required_user admin;
}
默认情况下,shiny的应用程序的运行是 shiny
用户,它在安装shiny-server时就已经被创建了。
如果需要指定其他用户来运行的话,需要run_as
来设置一下。
location / {
run_as tim;
}
还需要注意的是改变运行程序的用户后,程序所在的位置也应该能够被这个用户相应的权限才可以。
如果是使用shiny
用户来运行你的shiny
程序的话,你需要使用shiny
用户来安装R包,毕竟在此处总会涉及到权限的问题。
我自己测试过,使用shiny
作为运行用户,可以在root环境下安装R包,这样shiny程序仍然是可以运行的。
默认端口号是3838
。下面的例子是在配置文件中设置端口号80
server {
listen 80;
}
Location
的指令定义了shiny应用程序的存放位置以及所使用的URL链接。
比如,以下是定义了访问 http://localhost:3838/specialApp可以访问到存放在/srv/shiny-server/myApp
的shiny应用程序。
server {
...
# Define the location '/specialApp'
# 设置访问链接是/specialApp
location /specialApp {
# Run this location in 'app_dir' mode, which will host a single Shiny
# Application available at '/srv/shiny-server/myApp'
# 使用`app_dir`,指定其shiny应用程序的存放位置
app_dir /srv/shiny-server/myApp;
}
# Define the location '/otherApps'
location /otherApps {
# Run this location in 'site_dir' mode, which hosts the entire directory
# tree at '/srv/shiny-server/apps'
# 使用site_dir模式,可以将shiny程序放在这个指定的/srv/shiny-server/apps文件夹下,
# 访问的链接也会根据文件的路径来自动生成相应的URL链接
site_dir /srv/shiny-server/apps;
}
...
}
更新时间:2021-10-29