shiny在服务器上部署

将一个Shiny应用程序部署到服务器上可以通过多种方式实现,包括使用Shiny Server、Shinyapps.io或者Docker。以下是如何使用Shiny Server在服务器上部署Shiny应用程序的详细步骤。

步骤 1: 准备服务器环境

确保你的服务器运行的是Ubuntu或其他Linux发行版,并且你有sudo权限。

步骤 2: 安装R和Shiny

首先,更新系统并安装R:

bash 复制代码
sudo apt-get update
sudo apt-get install r-base

接着,安装Shiny包:

R 复制代码
install.packages("shiny")

步骤 3: 安装Shiny Server

下载并安装Shiny Server:

bash 复制代码
# 下载最新版本的Shiny Server
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

步骤 4: 配置Shiny Server

Shiny Server的默认配置文件位于/etc/shiny-server/shiny-server.conf。你可以编辑这个文件以更改服务器设置。例如,确保你的配置文件包含以下内容:

plaintext 复制代码
# 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 /srv/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;
  }
}

步骤 5: 部署你的Shiny应用

将你的Shiny应用程序放置在/srv/shiny-server目录中。例如,假设你的Shiny应用程序文件是app.R,你可以创建一个新的目录并将应用程序文件复制到该目录:

bash 复制代码
sudo mkdir /srv/shiny-server/myapp
sudo cp path/to/your/app.R /srv/shiny-server/myapp/

确保应用程序文件的所有权属于shiny用户:

bash 复制代码
sudo chown -R shiny:shiny /srv/shiny-server/myapp

步骤 6: 启动和管理Shiny Server

Shiny Server应该已经自动启动。如果没有,可以手动启动并检查其状态:

bash 复制代码
sudo systemctl start shiny-server
sudo systemctl status shiny-server

你可以使用以下命令来重启或停止Shiny Server:

bash 复制代码
sudo systemctl restart shiny-server
sudo systemctl stop shiny-server

步骤 7: 访问你的Shiny应用

现在,你可以通过访问服务器的IP地址和端口来访问你的Shiny应用。例如,如果你的服务器IP地址是123.45.67.89,你可以在浏览器中访问:

复制代码
http://123.45.67.89:3838/myapp

额外提示

  • 防火墙配置 :确保你的服务器防火墙允许通过3838端口的流量。例如,在Ubuntu上使用ufw

    bash 复制代码
    sudo ufw allow 3838
  • 反向代理:你可以设置一个反向代理(例如使用Nginx)来在标准的HTTP/HTTPS端口(80/443)上提供你的Shiny应用。

  • HTTPS :为了安全起见,你可以使用Let's Encrypt等工具为你的Shiny应用设置HTTPS。

通过上述步骤,你可以在服务器上成功部署一个Shiny应用程序。如果有任何问题或需要进一步的帮助,请随时提问。

相关推荐
序属秋秋秋23 分钟前
《Linux系统编程之系统导论》【冯诺依曼体系结构 + 操作系统基本概述】
linux·运维·服务器·c语言·ubuntu·操作系统·冯诺依曼体系结构
她说彩礼65万1 小时前
C# 特性详解
linux·服务器·c#
LSL666_3 小时前
5 Repository 层接口
android·运维·elasticsearch·jenkins·repository
电棍2336 小时前
在docker a100云服务器运行vulkan->sapien->robotwin的经验(报错segmentation fault)
运维·docker·容器
云动雨颤7 小时前
访问宝塔面板安全入口404?SSH命令轻松解决
linux·运维·安全
NPE~8 小时前
[Linux命令分享]日志查看 — — less
linux·运维·less·常用命令·日志查看
面向星辰8 小时前
扣子开始节点和结束节点
java·服务器·前端
一匹电信狗9 小时前
【C++】封装红黑树实现map和set容器(详解)
服务器·c++·算法·leetcode·小程序·stl·visual studio
大锦终9 小时前
【Linux】网络层与数据链路层中重点介绍
linux·运维·服务器·网络
lht63193561210 小时前
从Windows通过XRDP远程访问和控制银河麒麟 v10服务器
linux·运维·服务器·windows