golem icon indicating copy to clipboard operation
golem copied to clipboard

Shiny Server: Could not find a root 'DESCRIPTION' file that starts with '^Package'

Open JustGitting opened this issue 1 year ago • 3 comments

Describe the bug I've built a very simple shiny app with the Golem framework that successfully runs locally within Rstudio. However, when I try deploying it on a shiny-server, I get the following error in the logs.

su: ignoring --preserve-environment, it's mutually exclusive with --login
Error in `value[[3L]]()`:
! Could not find a root 'DESCRIPTION' file that starts with '^Package'
  in '/srv/shiny-server/mygolempackage'.
ℹ Are you in your project directory and does your project have a 'DESCRIPTION'
  file?
Backtrace:
     ▆
  1. └─shiny::runApp(Sys.getenv("SHINY_APP"), port = port, launch.browser = FALSE)
  2.   ├─shiny::as.shiny.appobj(appDir)
  3.   └─shiny:::as.shiny.appobj.character(appDir)
  4.     └─shiny::shinyAppDir(x)
  5.       └─shiny:::shinyAppDir_appR("app.R", appDir, options = options)
  6.         └─shiny (local) appObj()
  7.           └─shiny (local) func(fname, ...)
  8.             └─shiny:::sourceUTF8(fullpath, envir = new.env(parent = sharedEnv))
  9.               └─base::eval(exprs, envir)
 10.                 └─base::eval(exprs, envir)
 11.                   ├─shiny::..stacktraceon..(...)
 12.                   └─pkgload::load_all(export_all = FALSE, helpers = FALSE, attach_testthat = FALSE)
 13.                     └─pkgload::pkg_path(path)
 14.                       └─base::tryCatch(...)
 15.                         └─base (local) tryCatchList(expr, classes, parentenv, handlers)
 16.                           └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 17.                             └─value[[3L]](cond)
 18.                               └─cli::cli_abort(msg, class = "pkgload_no_desc")
 19.                                 └─rlang::abort(...)
Execution halted

To Reproduce I followed the advice deploying a golem package on a shiny-server https://github.com/ThinkR-open/golem/issues/145 using option 2 in the discussion.

Steps to reproduce the behavior:

  1. Execute golem::add_shinyserver_file() to create the app.R file in the root of the package.
  2. Build the package from source within RStudio.
  3. Copy the created package file mygolempackage.tar.gz to the shiny server.
  4. Install the package for all users on the server by executing sudo su - -c "R -e \"install.packages('/home/user/Downloads/mygolempackage.0.0.1.tar.gz', repos=NULL)\""
  5. Copy the app.R file from the local machine to the shiny server app folder, /srv/shiny-server/mygolempackage/

The app.R contains the following code:

$ cat app.R
# Launch the ShinyApp (Do not remove this comment)
# To deploy, run: rsconnect::deployApp()
# Or use the blue button on top of this file

pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE)
options( "golem.app.prod" = TRUE)
mygolempackage::run_app() # add parameters here (if any)

  1. Visit the shiny-server URL, e.g. https://my.shinyserver.com/mygolempackage/

Expected behavior Application should work.

Screenshots I get the following error message on the webpage:

An error has occurred

The application failed to start.

The application exited during initialization.

Server session info

$ R
...
> devtools::session_info()
─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.3.2 (2023-10-31)
 os       Ubuntu 20.04.6 LTS
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Australia/Melbourne
 date     2023-12-08
 pandoc   2.5 @ /usr/bin/pandoc

─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 cachem        1.0.8   2023-05-01 [1] CRAN (R 4.3.2)
 callr         3.7.3   2022-11-02 [2] CRAN (R 4.2.2)
 cli           3.6.1   2023-03-23 [2] CRAN (R 4.2.3)
 crayon        1.5.2   2022-09-29 [2] CRAN (R 4.2.1)
 devtools      2.4.5   2022-10-11 [1] CRAN (R 4.3.2)
 digest        0.6.33  2023-07-07 [1] CRAN (R 4.3.2)
 ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.2.2)
 fastmap       1.1.1   2023-02-24 [1] CRAN (R 4.2.2)
 fs            1.6.3   2023-07-20 [1] CRAN (R 4.3.2)
 glue          1.6.2   2022-02-24 [2] CRAN (R 4.1.2)
 htmltools     0.5.7   2023-11-03 [1] CRAN (R 4.3.2)
 htmlwidgets   1.6.4   2023-12-06 [1] CRAN (R 4.3.2)
 httpuv        1.6.13  2023-12-06 [1] CRAN (R 4.3.2)
 later         1.3.2   2023-12-06 [1] CRAN (R 4.3.2)
 lifecycle     1.0.4   2023-11-07 [2] CRAN (R 4.3.2)
 magrittr      2.0.3   2022-03-30 [2] CRAN (R 4.1.3)
 memoise       2.0.1   2021-11-26 [1] CRAN (R 4.2.2)
 mime          0.12    2021-09-28 [1] CRAN (R 4.2.2)
 miniUI        0.1.1.1 2018-05-18 [1] CRAN (R 4.3.2)
 pkgbuild      1.4.2   2023-06-26 [2] CRAN (R 4.3.1)
 pkgload       1.3.3   2023-09-22 [1] CRAN (R 4.3.2)
 prettyunits   1.2.0   2023-09-24 [2] CRAN (R 4.3.1)
 processx      3.8.2   2023-06-30 [2] CRAN (R 4.3.1)
 profvis       0.3.8   2023-05-02 [1] CRAN (R 4.3.2)
 promises      1.2.1   2023-08-10 [1] CRAN (R 4.3.2)
 ps            1.7.5   2023-04-18 [2] CRAN (R 4.3.0)
 purrr         1.0.1   2023-01-10 [1] CRAN (R 4.2.3)
 R6            2.5.1   2021-08-19 [2] CRAN (R 4.1.1)
 Rcpp          1.0.11  2023-07-06 [2] CRAN (R 4.3.1)
 remotes       2.4.2.1 2023-07-18 [1] CRAN (R 4.3.2)
 rlang         1.1.2   2023-11-04 [2] CRAN (R 4.3.2)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.3.2)
 shiny         1.8.0   2023-11-17 [1] CRAN (R 4.3.2)
 stringi       1.8.2   2023-11-23 [1] CRAN (R 4.3.2)
 stringr       1.5.1   2023-11-14 [1] CRAN (R 4.3.2)
 urlchecker    1.0.1   2021-11-30 [1] CRAN (R 4.3.2)
 usethis       2.2.2   2023-07-06 [1] CRAN (R 4.3.2)
 vctrs         0.6.5   2023-12-01 [1] CRAN (R 4.3.2)
 xtable        1.8-4   2019-04-21 [1] CRAN (R 4.2.2)

 [1] /usr/local/lib/R/site-library
 [2] /usr/lib/R/site-library
 [3] /usr/lib/R/library
$ shiny-server --version
Shiny Server v1.5.20.1002
Node.js v16.18.1

Any suggestions would be appreciated as I may have done something wrong along the way.

JustGitting avatar Dec 08 '23 11:12 JustGitting

I've found a solution by commenting out the load_all() and options() calls.

$ cat app.R
# Launch the ShinyApp (Do not remove this comment)
# To deploy, run: rsconnect::deployApp()
# Or use the blue button on top of this file

# pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE)
# options( "golem.app.prod" = TRUE)
mygolempackage::run_app() # add parameters here (if any)

I'm still a novice regarding package development so I don't understand why golem::add_shinyserver_file(pkg = get_golem_wd(), open = TRUE) adds load_all to the app.R.

Could the documentation be updated to explain what it is for and how to setup the package on a shiny-server so when it is deployed, load_all() works?

JustGitting avatar Dec 10 '23 23:12 JustGitting

Hello @JustGitting ,

The pkgload::load_all function simulates the installation of your package during development.

The error seems to say that the function is unable to find the DESCRIPTION file in the folder where the app.R file is located.

Have you unzipped the mygolempackage.tar.gz package?

ArthurData avatar Dec 15 '23 15:12 ArthurData

Hi @ArthurData,

Sorry I hadn't got back to you, Christmas and all...

Indeed, I didn't copy any package source files to the app.R directory. I had assumed it wasn't necessary as I had installed the package via install.packages().

It makes sense now, but it wasn't clear from the documentation that the original app.R created by golem::add_shinyserver_file() includes extra function calls for development purposes.

Could the documentation be updated to note the golem::add_shinyserver_file() functions are for helping with testing / development and the required package source files also need to be copied to where app.R is?

Is it possible to add an option to golem::add_*() that disables the creation of the extra function calls in app.R? e.g. golem::add_shinyserver_file(production = True)

JustGitting avatar Jan 05 '24 03:01 JustGitting

Hey @JustGitting,

Thanks for reporting 🫶

The output of the function is the following, the last line indeed signals that the whole package should be uploaded to the server.

> golem::add_shinyserver_file() 
── Creating _disable_autoload.R ────────────────
✔ Created
✔ Adding '^app\\.R$' to '.Rbuildignore'
✔ Adding '^rsconnect$' to '.Rbuildignore'
✔ Adding 'pkgload' to Imports field in DESCRIPTION
• Refer to functions with `pkgload::fun()`
✔ File created at /private/tmp/deleteme/app.R
To deploy, run:
• rsconnect::deployApp()

• Note that you'll need to upload the whole package to Shiny Server

That being said, I feel like this is not enough, and that the app.R should include this information.

I'm opening a new issue to track this fix.

ColinFay avatar Jun 21 '24 09:06 ColinFay