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

相关推荐
jimy18 分钟前
Oracle的VM.Standard.E2.1.Micro虚拟机创建后,必要的安全设置,卸snap省内存
服务器·安全
songx_999 分钟前
Linux基础3
linux·运维·服务器
拾光Ծ17 分钟前
【Linux系统】进程信号(下):信号处理与“操作系统运行原理”
linux·运维·服务器·信号处理·操作系统原理
Cat_Rocky17 分钟前
ingress service配置解析
linux·服务器·网络
小冷爱学习!17 分钟前
Apache Shiro 1.2.4 反序列化漏洞Shiro-550(CVE-2016-4437)
服务器·网络·python·安全·网络安全·apache
|_⊙19 分钟前
Linux 进程知识扩展(下)
linux·运维·服务器
思麟呀24 分钟前
初始MySQL数据库
服务器·数据库·mysql
沪漂阿龙27 分钟前
自动化评测:RAGAS 或 DeepEval,怎么把 RAG 系统从“感觉还行”变成“数据说话”
运维·人工智能·自动化
IMPYLH32 分钟前
Linux 的 tsort 命令
linux·运维·服务器·bash
The Straggling Crow32 分钟前
Linux foundation + PXE 2026-05-08
linux·运维·服务器