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应用程序。如果有任何问题或需要进一步的帮助,请随时提问。

相关推荐
likfishdn6 分钟前
Linux的文件与目录管理
linux·运维·服务器
渲染101专业云渲染7 分钟前
川翔云电脑优势总结
服务器·3d·电脑·blender·maya
chian-ocean25 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=27 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
橘子味的茶二36 分钟前
高级系统架构师--第十章:计算机网络
服务器·计算机网络·系统架构
紫菜(Nori)1 小时前
短连接服务器压测-wrk
服务器·压力测试
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos
北京耐用通信1 小时前
航空装配自动化神器Ethercat转profient网关搭配机器人精准控制
运维·机器人·自动化
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net