部署含自定义R包的Shiny应用至shinyapps.io遇错误求助
Let’s work through this step by step—your local setup works, so the issue is almost certainly how shinyapps.io is trying to install and access your NxT package. Here’s what to check and fix:
1. Verify Your GitHub Repository Structure
The error "Does not appear to be an R package (no DESCRIPTION)" tells us shinyapps.io can’t find your package’s core metadata file in your GitHub repo.
- Double-check your GitHub repo: Open your repo at
github.com/zertupo/NxTand confirm theDESCRIPTIONfile,NAMESPACE, andR/folder are all in the root directory (not nested inside a subfolder likeNxT/NxT/). - Test locally first: Run
devtools::install_github("zertupo/NxT")on your machine. If this fails, fix your repo structure before trying to deploy again. If it works locally, the repo structure is correct, and we can move to the next step.
2. Declare Dependencies Properly (The Right Way)
shinyapps.io builds your app’s environment before launching it—running install_github() inside your server.R or ui.R runs too late (during app runtime, not build time). Instead, use one of these two reliable methods:
Method 1: Use a Shiny App DESCRIPTION File (Recommended)
Create a DESCRIPTION file in your Shiny app’s root directory (separate from your package’s DESCRIPTION). This tells shinyapps.io exactly what dependencies to install during the build phase:
Package: MyShinyApp Type: Shiny Title: Your App Name Version: 0.1.0 Authors@R: person("Aurélien", "your-email@example.com", role = c("aut", "cre")) Description: Shiny app using the custom NxT package. Depends: shiny Imports: NxT Remotes: zertupo/NxT
When you deploy, shinyapps.io will automatically pull and install NxT from GitHub, along with any dependencies listed in your package’s DESCRIPTION.
Method 2: Install in global.R (Backup Option)
If you prefer not to use a DESCRIPTION file, create a global.R in your app directory with this code to install the package during the build phase:
# Install devtools and NxT if missing if (!requireNamespace("devtools", quietly = TRUE)) { install.packages("devtools") } if (!requireNamespace("NxT", quietly = TRUE)) { devtools::install_github("zertupo/NxT", dependencies = TRUE) } library(NxT)
This ensures the package is installed before your app’s server or ui code runs.
3. Re-Deploy and Check Logs
- Use
rsconnect::deployApp()(or the RStudio "Publish" button) to re-upload your app with the new setup. - If you still see errors, check the full logs in shinyapps.io: Go to your app’s dashboard, click "Logs", and look for detailed installation errors (like missing dependencies in your
NxTpackage’sDESCRIPTION).
Quick Troubleshooting Checklist
- Confirm your
NxTpackage’sDESCRIPTIONlists all its own dependencies (e.g., if it usesdplyr, adddplyrtoImportsin the package’sDESCRIPTION). - Make sure your GitHub repo is public (shinyapps.io can’t access private repos without additional authentication).
内容的提问来源于stack exchange,提问作者Aurélien

