惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
Cisco Talos Blog
Cisco Talos Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
D
Docker
S
SegmentFault 最新的问题
博客园 - 聂微东
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The GitHub Blog
The GitHub Blog
GbyAI
GbyAI
L
LangChain Blog
Vercel News
Vercel News
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
T
Threat Research - Cisco Blogs
T
Threatpost
Scott Helme
Scott Helme
T
Tailwind CSS Blog
Latest news
Latest news
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
The Register - Security
The Register - Security
罗磊的独立博客
P
Proofpoint News Feed
腾讯CDC
S
Schneier on Security
雷峰网
雷峰网
A
About on SuperTechFans
T
Tenable Blog
F
Full Disclosure
Cyberwarzone
Cyberwarzone
博客园_首页
有赞技术团队
有赞技术团队
K
Kaspersky official blog

Yorksite

Plog004:好吃好吃 · Plog Plog003:Until Then · Plog Plog002:春天花会开 · Plog Plog001:让人疲惫的AI与在战锤世界中仰泳,赞美欧姆尼赛亚? · Plog rhaeTree:一个基于 Rust 的进化树可视化编辑工具 · Articles 我的键盘快捷键们 · Articles 迟到的2025年度数码产品总结 · Articles 关于我和这个博客 · Info 买了一只十多年前的老 Pebble · Articles 盘点一下今年让我上头的那些游戏 · Articles 【吃了啥】新利查西菜馆 · Articles 根据Zotero数据库追踪新发表文献 · Articles 解决远程服务器上Singularity联网问题 · Articles 又是一个Mac软件列表 · Articles Vita3K存档转移到PSV实机 · Articles SnapGene创建多外显子基因结构 · Articles Rstudio也能用GitHub Copilot了 · Articles 双十一买了啥 · Articles 文献一团乱麻?试试PARA管理方法 · Articles 点名的风还是吹到了Blog · Articles 从Raindrop迁移到了Anybox · Articles 数据可视化——基本图形元素及其应用 · Articles 单变量异常值检测方法 复现一张相关性图 · Articles 【读文献】单细胞分析最佳实践 · Articles 部署预印本追踪 TRxiv 到 Github Action Hello, again · Articles 1 dataset 100 visualizations 中有意思的可视化 · Articles 论文可视化配色简易指南 Karabiner 助力,让你的键盘操作快人一步 · Articles 我的植物组学数据库合集 Ver.20220528 · Articles 利用 n8n 打造飞书 RSS 推送机器人 「#」的前世今生
Docker 打包 Shiny App · Articles
2023-03-28 · via Yorksite

Published Mar 28, 2023

2 minutes read

文件准备

将Shiny用到的server.Rui.R一起放在app文件夹中

./app:
server.R ui.R

写个Dockerfile,把用到的包都写在 install.r 后面

FROM rocker/r-base:latest
LABEL maintainer="email <example@mail.com>"
RUN apt-get update && apt-get install -y --no-install-recommends \
    sudo \
    libcurl4-gnutls-dev \
    libcairo2-dev \
    libxt-dev \
    libssl-dev \
    libssh2-1-dev \
    && rm -rf /var/lib/apt/lists/*
RUN install.r shiny shinyBS dplyr stringr
RUN echo "local(options(shiny.port = 3838, shiny.host = '0.0.0.0'))" > /usr/lib/R/etc/Rprofile.site
RUN addgroup --system app \
    && adduser --system --ingroup app app
WORKDIR /home/app
COPY app .
RUN chown app:app -R /home/app
USER app
EXPOSE 3838
CMD ["R", "-e", "shiny::runApp('/home/app')"]

按以下方式进行构建

# name of the image
export IMAGE="yorks0n/trxiv_shiny"
 
# build image
docker build -t $IMAGE .
 
# run and test locally
docker run -p 8080:3838 $IMAGE

居然就行了!

部署在 Railway 上

# 安装
brew install railway
 
# 登录
railway login

创建一个项目,并输入项目名称

 railway init
> Project Name TRxiv_shiny
Created project TRxiv_shiny on Personal

虽然当前目录下有个 Dockerfile 了,但是这 XX 的 railway 部署时候端口和默认 docker 的不太一样,或者我没找到哪里设置,所以如果要部署在 railway 上,还需要改一下 Dockerfile。虽然在这指定了ENV PORT=3838,但实际上 railway 每次开的端口都不太一样,所以标准 docker 的写法不太行。

FROM rocker/r-base:latest
LABEL maintainer="Yorkson <yorks0n@qq.com>"
RUN apt-get update && apt-get install -y --no-install-recommends \
    sudo \
    libcurl4-gnutls-dev \
    libcairo2-dev \
    libxt-dev \
    libssl-dev \
    libssh2-1-dev \
    && rm -rf /var/lib/apt/lists/*
RUN install.r shiny shinyBS dplyr stringr
RUN addgroup --system app \
    && adduser --system --ingroup app app
WORKDIR /home/app
COPY app .
RUN chown app:app -R /home/app
USER app
EXPOSE 3838
ENV PORT=3838
# 研究后发现,这里以获取PORT的方式,才能在 Railway 中部署
CMD ["R", "-e", "shiny::runApp('/home/app', host = '0.0.0.0', port=as.numeric(Sys.getenv('PORT')))"]
railway up

参考资料

在Windows系统下,基于WLS从零开始部署我的 R shiny项目到 Docker 中,并将镜像发布到 Docker Hub(内附详细操作流程)_douerw的博客-CSDN博客

Dockerizing Shiny Applications

Dockerized Shiny Apps with Dependencies