You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用R/exams包的Shiny应用部署到shinyapps.io时包依赖错误如何解决

报错原因

Error: Unhandled Exception: Child Task 980776811 failed: Error building image: Error fetching exams (2.4-0) source. unable to satisfy package: exams (2.4-0)
该报错是因为shinyApps.io默认仅从CRAN拉取R包依赖,你使用的exams 2.4-0是R-Forge提供的开发版本,不在CRAN的默认包源检索范围内,因此部署时无法找到对应安装包。

解决方案

可根据你的使用场景选择以下任意一种方法解决:

  • 方法1:使用remotes指定源安装
    在你的Shiny应用入口文件(一般为app.R)最顶部添加以下代码,部署时会自动从指定地址拉取对应版本的exams包:
if (!requireNamespace("remotes", quietly = TRUE)) {
  install.packages("remotes", repos = "https://cran.rstudio.com/")
}
if (!requireNamespace("exams", quietly = TRUE) || packageVersion("exams") != "2.4-0") {
  remotes::install_url("http://R-Forge.R-project.org/src/contrib/exams_2.4-0.tar.gz")
}
  • 方法2:部署前配置包源后用命令行发布
    在本地R控制台运行以下代码,将R-Forge加入包源列表后直接通过命令部署,rsconnect会自动识别额外包源拉取依赖:
# 配置包源
options(repos = c(
  CRAN = "https://cran.rstudio.com/",
  RForge = "http://R-Forge.R-project.org"
))
# 执行部署,替换括号内内容为你的应用本地目录路径
rsconnect::deployApp(appDir = "你的Shiny应用本地目录路径")
  • 方法3:使用本地源码包安装
    先在本地将exams 2.4-0打包为源码压缩包,放在Shiny应用根目录后,在入口文件顶部添加本地安装代码:
if (!requireNamespace("exams", quietly = TRUE) || packageVersion("exams") != "2.4-0") {
  install.packages("exams_2.4-0.tar.gz", repos = NULL, type = "source")
}
注意事项
  • 部署前建议先在本地卸载已有的exams包,重新安装对应2.4-0版本,避免本地包版本记录异常导致rsconnect识别错误。
  • 若后续CRAN的exams包更新到2.4-0及以上版本,可直接切换为CRAN源安装,无需额外配置。

内容的提问来源于stack exchange,提问作者Ruben。

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.10 00:15:00