My Email: 2421547970@qq.com

Copyright© 2024 All Rights Reserved.

苏ICP备2024148111号-1

介绍

shiny部署流程。

代码


# rstudio server 安装    
sudo apt-get install r-base
sudo apt-get install gdebi-core
wget https://download2.rstudio.org/server/focal/amd64/rstudio-server-2024.04.2-764-amd64.deb
sudo gdebi rstudio-server-2024.04.2-764-amd64.deb
## 上一步可能会出现报错
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Reading state information... Done
This package is uninstallable
Dependency is not satisfiable: libssl1.0.0|libssl1.0.2|libssl1.1
## 解决方法
###手动安装libssl1.1
sudo apt-get install libssl1.1
###可能库中没有这个包,所以要手动添加    http://security.ubuntu.com/ubuntu/pool/main/o/openssl/    网站上下载适合的版本
wget http://security.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1-1ubuntu2.1\~18.04.20_amd64.deb
sudo dpkg -i libssl1.1_1.1.1-1ubuntu2.1\~18.04.20_amd64.deb
## 重复命令即可安装成功
sudo gdebi rstudio-server-2024.04.2-764-amd64.deb
## 在腾讯云控制台开放8787端口


# shiny包安装 进入r
options(repos = c(CRAN = "https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
install.packages("shiny")

# 安装shiny server   官网https://posit.co/download/shiny-server/   下载后传输到服务器
sudo gdebi shiny-server-1.5.22.1017-amd64.deb

# 为了在shiny应用出错时能显示具体的错误信息,我们需要修改shiny server的配置文件
vim /etc/shiny-server/shiny-server.conf
## 添加以下内容
sanitize_errors false;
preserver-logs true;

# ngnix 反向代理
cd /etc/nginx/sites-available
sudo vim shiny.conf
## 添加配置信息:  (引用了未定义的变量 connection_upgrade) 所以要在/etc/nginx/nginx.conf定义
server {
    # listen 80 means the Nginx server listens on the 80 port.
    listen 80;
    listen [::]:80;
    # Replace it with your (sub)domain name.
    server_name bnapus-zju.com;
    # The reverse proxy, keep this unchanged:
    location / {
        proxy_pass http://localhost:3838;
        proxy_redirect http://localhost:3838/ $scheme://$host/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_read_timeout 20d;
        proxy_buffering off;
    }
}
## 在/etc/nginx/nginx.conf http 块内添加以下代码:
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }



# 软链接
cd ../sites-enabled
sudo ln -s ../sites-available/shiny.conf

# 验证ngnix配置
sudo nginx -t
sudo systemctl restart nginx
## 出现以下内容即为成功
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


# 重启shiny-server
sudo systemctl restart shiny-server


# 要用root安装r包,否则项目打不开
## 修改r包安装路径 必须要安装在/usr/lib/R/library/ 中才有用
###修改install的镜像
###打开 ~/.Rprofile    (没有的话创建一个)
##添加     .libPaths(c("~/R_packages", "~/R_packages1"))

#设置 CRAN 镜像
local({
  r <- getOption("repos")
  r["CRAN"] <- "http://mirrors.tuna.tsinghua.edu.cn/CRAN/"
  options(repos = r)
})
#设置 Bioconductor 镜像
options(BioC_mirror = "http://mirrors.ustc.edu.cn/bioc/")