rstudio / rsconnect

Publish Shiny Applications, RMarkdown Documents, Jupyter Notebooks, Plumber APIs, and more
http://rstudio.github.io/rsconnect/
132 stars 81 forks source link

Unable to deploy using library() with quosure #406

Closed leungi closed 4 years ago

leungi commented 4 years ago

Both methods below work in interactive session, but method 2 fails when deploying via RS Connect.

1) This works, as expected

library("tidylog")
library("tidyverse")
library("lubridate")
library("readxl")
library("janitor")
library("tictoc")
library("plotly")
library("reactable")

2) This fails

load_pkg <- rlang::quos(tidyverse, tidylog, lubridate, readxl, janitor, tictoc)

invisible(lapply(lapply(load_pkg, rlang::quo_name), library, character.only = TRUE))

RS Connect log

2020/02/13 08:55:21.998634284 linux distribution: Red Hat Enterprise Linux Server release 7.3 (Maipo) 
2020/02/13 08:55:22.001685942 Using Packrat dir /opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/3.6.2
2020/02/13 08:55:22.010001493 Server version: 1.7.8-7
2020/02/13 08:55:22.010028150 LANG: en_US.UTF-8
2020/02/13 08:55:22.010067907 R version: 3.6.2
2020/02/13 08:55:22.010085106 shiny version: 1.4.0
2020/02/13 08:55:22.010086437 httpuv version: 1.5.2
2020/02/13 08:55:22.010100653 rmarkdown version: 2.0
2020/02/13 08:55:22.010111577 knitr version: 1.26
2020/02/13 08:55:22.010131667 jsonlite version: 1.6
2020/02/13 08:55:22.010134857 RJSONIO version: (none)
2020/02/13 08:55:22.010150324 htmltools version: 0.4.0
2020/02/13 08:55:22.010473338 Using pandoc at /opt/rstudio-connect/ext/pandoc2
2020/02/13 08:55:22.193358732 Using jsonlite for JSON processing
2020/02/13 08:55:22.203863621 Using Shiny bookmarking base directory /opt/rstudio-connect/mnt/bookmarks
2020/02/13 08:55:22.204096494 
2020/02/13 08:55:22.204100089 Starting R with process ID: '22413'
2020/02/13 08:55:22.279360875 
2020/02/13 08:55:22.279371106 Listening on http://127.0.0.1:40046
2020/02/13 08:55:22.780956627 
2020/02/13 08:55:23.159828262 
2020/02/13 08:55:23.159839580 
2020/02/13 08:55:23.159874485 processing file: app.Rmd
2020/02/13 08:55:23.171331689 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |...                                                                   |   4%
2020/02/13 08:55:23.171566969    inline R code fragments
2020/02/13 08:55:23.171571675 
2020/02/13 08:55:23.173384158 
  |                                                                            
  |......                                                                |   8%
2020/02/13 08:55:23.175006582 label: setup (with options) 
2020/02/13 08:55:23.196819831 List of 1
2020/02/13 08:55:23.198829855  $ include: logi FALSE
2020/02/13 08:55:23.198879757 
2020/02/13 08:55:23.220791290 Quitting from lines 13-42 (app.Rmd) 
2020/02/13 08:55:23.221987809 
2020/02/13 08:55:23.225197404 Warning: Error in FUN: there is no package called 'tidyverse'
2020/02/13 08:55:23.243415122   153: <Anonymous>
2020/02/13 08:55:29.380166403 
2020/02/13 08:55:29.670811665 
2020/02/13 08:55:29.670822415 
2020/02/13 08:55:29.670851427 processing file: app.Rmd
2020/02/13 08:55:29.682004736 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |...                                                                   |   4%
2020/02/13 08:55:29.682059879    inline R code fragments
2020/02/13 08:55:29.682064643 
2020/02/13 08:55:29.682599632 
  |                                                                            
  |......                                                                |   8%
2020/02/13 08:55:29.683233876 label: setup (with options) 
2020/02/13 08:55:29.683454163 List of 1
2020/02/13 08:55:29.684277884  $ include: logi FALSE
2020/02/13 08:55:29.684315311 
2020/02/13 08:55:29.699705559 Quitting from lines 13-42 (app.Rmd) 
2020/02/13 08:55:29.700729016 
2020/02/13 08:55:29.703711920 Warning: Error in FUN: there is no package called 'tidyverse'
2020/02/13 08:55:29.710396628   153: <Anonymous>
2020/02/13 08:55:41.814877150 
2020/02/13 08:55:42.097858591 
2020/02/13 08:55:42.097869149 
2020/02/13 08:55:42.097904260 processing file: app.Rmd
2020/02/13 08:55:42.108740923 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |...                                                                   |   4%
2020/02/13 08:55:42.108797342    inline R code fragments
2020/02/13 08:55:42.108801183 
2020/02/13 08:55:42.109333247 
  |                                                                            
  |......                                                                |   8%
2020/02/13 08:55:42.109990207 label: setup (with options) 
2020/02/13 08:55:42.110217440 List of 1
2020/02/13 08:55:42.111045067  $ include: logi FALSE
2020/02/13 08:55:42.111063682 
2020/02/13 08:55:42.126236767 Quitting from lines 13-42 (app.Rmd) 
2020/02/13 08:55:42.127276678 
2020/02/13 08:55:42.130237703 Warning: Error in FUN: there is no package called 'tidyverse'
2020/02/13 08:55:42.136908341   153: <Anonymous>
2020/02/13 08:56:16.810297650 Error code: render-missing-r-package

A package is missing from the R environment.

Possible causes:
* The package is referenced indirectly in the R code, without an explicit library() or require() call.

Possible solutions:
* Import required libraries directly. For example, using "library(tidyverse)".

References:
* https://www.rdocumentation.org/packages/base/versions/3.6.1/topics/library
* https://support.rstudio.com/hc/en-us/articles/229998627-Why-does-my-app-work-locally-but-not-on-my-RStudio-Connect-server

2020/02/13 08:56:16.810297650 Additional data:
Package: 'tidyverse'
Found in the following log entry:
2020/02/13 08:55:23.225197404 Warning: Error in FUN: there is no package called 'tidyverse'
kevinushey commented 4 years ago

This is expected. rsconnect relies on Packrat to infer an application's R package dependencies, and this will fail if you load your packages in creative ways.

The diagnostic report at the end of the deployment is accurate and indicates how the problem can be fixed.

leungi commented 4 years ago

Noted; will stick with library().

Thanks for prompt reply.

kevinushey commented 4 years ago

I'm glad I could help!

As an aside, I think I may off been a bit curt in my reply; I'm sorry for that. The crux of the matter is indeed that we do rely on static analysis of the R code in an application in order to infer the application's R package dependencies, and that static analysis does fail when packages are loaded in non-typical ways.

leungi commented 4 years ago

@kevinushey: Appreciate your consideration; I'm not offended at all 😉.

I totally fail on K.I.S.S. principle!