rstudio / rsconnect

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

writeManifest does not pick up package used in a {config} expression #655

Closed boshek closed 1 year ago

boshek commented 1 year ago

:wave: thanks for such a helpful utility for working with Connect.

I've been starting to use the {config} package more lately to manage different behaviour between Connect and locally. So if we have an example config file like this:

config.yml

default:
  data: !expr datasets::iris

production:
  data: !expr ggplot2::diamonds

I can call a quarto doc (using both states for illustration)"

tester.qmd

---
format: html
---

```{r}
config::get("data")
Sys.setenv(R_CONFIG_ACTIVE = "production")

config::get("data")

The key thing to note here is that in "production" I am actually calling an external library (namely ggplot2). All this code work fine except when I deploy to Connect because `writeManifest` does not pick up the ggplot2 dependency from this call:

```r
rsconnect::writeManifest(
    appFiles = c("tester.qmd", "config.yml"),
    quarto = quarto::quarto_path()
)

Is there anyway add that dependency to the manifest or am I just overloading the config.yml?

aronatkins commented 1 year ago

Unfortunately, you will need to add library statements to your tester.qmd file in order for the dependencies to be detected. For your example, you will need:

library(datasets)
library(ggplot2)

I'm including both packages here because the target config is assigned on the server, not on the client.

We originally filed this as a packrat issue (https://github.com/rstudio/packrat/issues/510), but this type of discovery also looks to be missing in renv.

CC @kevinushey - should renv look into config.yml files when the config package is in use?

aronatkins commented 1 year ago

I've created https://github.com/rstudio/renv/issues/1140 for renv tracking and discussion; if we do add this capability to renv, we will subsequently need to update packrat to use that new version.

boshek commented 1 year ago

Thanks! I am using that workaround to explicitly load packages. I just know that that added manual steps will frequently be forgotten ;).

And oops yes {datasets} wasn't really a good default example here. Thanks for seeing what I meant.

hadley commented 1 year ago

Closed as we're tracking in renv.