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

相关推荐
_星辰大海乀5 小时前
IP 协议
服务器·网络·tcp/ip·nat·子网掩码·ip协议
屿行屿行6 小时前
【Linux】Socket编程(基于实际工程分析)
linux·服务器·网络
runepic6 小时前
Python + PostgreSQL 批量图片分发脚本:分类、去重、断点续拷贝
服务器·数据库·python·postgresql
企鹅侠客7 小时前
Linux性能调优 详解磁盘工作流程及性能指标
linux·运维·服务器·性能调优
企鹅侠客7 小时前
Linux性能调优 再谈磁盘性能指标和进程级IO
linux·运维·服务器·性能调优
虚伪的空想家7 小时前
云镜像,虚拟机镜像怎么转换成容器镜像
服务器·docker·容器·k8s·镜像·云镜像·虚机
不过普通话一乙不改名8 小时前
Linux 网络收包的进阶之路:从普通 socket 到 AF_XDP 零拷贝
linux·运维·网络
在路上@Amos8 小时前
Linux 命令行查看 串口hex数据
linux·运维·服务器
人工智能训练8 小时前
Linux 系统核心快捷键表(可打印版)
linux·运维·服务器·人工智能·ubuntu·容器·openeuler
Vanranrr9 小时前
C++临时对象与悬空指针:一个导致资源加载失败的隐藏陷阱
服务器·c++·算法