Vetiver deployment to Connect issue

Hi All,

I am having some issues with deploying a test model to Connect using vetiver. Code im using is as per examples provided;

#part 1 - CREATE SIMPLE MODEL
library(parsnip)
library(workflows)
library(tidyverse)
library(tidymodels)
library(vetiver)

data(Sacramento, package = "modeldata")
sac<-Sacramento

#split data in to train, test and validation
set.seed(1353)
sac_split <- initial_split(sac, strata = price)
sac_train <- training(sac_split)
sac_test <- testing(sac_split)

## for model to training set
rf_spec <- rand_forest(mode = "regression")
rf_form <- price ~ type + sqft + beds + baths

rf_fit <- 
  workflow(rf_form, rf_spec) %>%
  fit(sac_train)

#Now that our model is trained, we can estimate the model performance we expect to see on new data using our testing data.

rf_metric_set <- metric_set(rmse, rsq, ccc, mae)
rf_metrics <-
  augment(rf_fit, new_data = sac_test) %>%
  rf_metric_set(truth = price, estimate = .pred)

#create vetver version of model with metrics as metadata
v_rf <- vetiver_model(rf_fit, model_name = "house_price_model_rf", metadata = list(metrics = rf_metrics))
model_board <- board_connect(auth = "envvar", server = Sys.getenv("CONNECT_SERVER") ,versioned = TRUE)
model_board %>% vetiver_pin_write(v_rf)

First issue is that i cant use the vetiver_deploy_rsconnect() deployment method as the following results in error "Error: Multiple accounts with the name 'USERNAME' exist. Please specify the server of the account you wish to use. ";

vetiver::vetiver_deploy_rsconnect(model_board,"USERNAME/house_price_model_rf", account = "USERNAME",predict_args = list(debug = TRUE))

I have got around by using the vetiver_write_plumber() call;
vetiver_write_plumber(model_board, "USERNAME/house_price_model_rf", file = "plumber.R")

But for this model connect gives me the following error;
###ERROR LOG

2023/08/11 12:43:40 PM:
2023/08/11 12:43:41 PM: Error in map_chr(bad, "package") : ℹ In index: 1.
2023/08/11 12:43:41 PM: Caused by error:
2023/08/11 12:43:41 PM: Plumber API exiting ...
2023/08/11 12:43:41 PM: ! Result must be length 1, not 0.
2023/08/11 12:43:41 PM: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
2023/08/11 12:43:41 PM: Execution halted

Anyone got anu points on either issue please?
Thanks

I also have multiple accounts, multiple servers, etc! Kind of a pain sometimes. :laughing:

The way I successfully deploy to a given Connect server is by specifying these in the dots of vetiver_deploy_rsconnect():

library(vetiver)
cars_lm <- lm(mpg ~ ., data = mtcars)
v <- vetiver_model(cars_lm, "julia.silge/mtcars-vetiver-example")

library(pins)
board <- board_connect()
#> Connecting to Posit Connect 2023.05.0 at <https://colorado.posit.co/rsc>
vetiver_pin_write(board, v)
#> Writing to pin 'julia.silge/mtcars-vetiver-example'
#> 
#> Create a Model Card for your published model
#> • Model Cards provide a framework for transparent, responsible reporting
#> • Use the vetiver `.Rmd` template as a place to start
vetiver_deploy_rsconnect(
    board, 
    "julia.silge/mtcars-vetiver-example", 
    account = "julia.silge", 
    server = "colorado.posit.co"
)
#> ── Preparing for deployment ────────────────────────────────────────────────────
#> ✔ Re-deploying "vetiver" to "server: colorado.posit.co / username: julia.silge"
#> ℹ Looking up application with id 15890...
#> ✔ Found application <https://colorado.posit.co/rsc/mtcars-vetiver-example-api/>
#> ℹ Bundling 1 file: 'plumber.R'
#> ℹ Capturing R dependencies with renv
#> ✔ Found 57 dependencies
#> ✔ Created 25,680b bundle
#> ℹ Uploading bundle...
#> ✔ Uploaded bundle with id 78402
#> ── Deploying to server ─────────────────────────────────────────────────────────
#> Building Plumber API...
#> Bundle created with R version 4.2.2 is compatible with environment Kubernetes::ghcr.io/rstudio/content-pro:r4.2.2-py3.11.3-ubuntu2204 with R version 4.2.2 from /opt/R/4.2.2/bin/R 
#> Bundle requested R version 4.2.2; using /opt/R/4.2.2/bin/R from Kubernetes::ghcr.io/rstudio/content-pro:r4.2.2-py3.11.3-ubuntu2204 which has version 4.2.2
#> Performing manifest.json to packrat transformation.
#> Determining session server location ...
#> Connecting to session server http://service-f23cc8d4-d638-42cf-88ac-791eafbf43e3.rstudio-connect:50734 ...
#> [rsc-session] Content GUID: fffe3b44-03fd-4e43-be64-93a0cae3e930
#> [rsc-session] Content ID: 15890
#> [rsc-session] Bundle ID: 78402
#> Connected to session server http://service-f23cc8d4-d638-42cf-88ac-791eafbf43e3.rstudio-connect:50734
#> whoami: cannot find name for user ID 999
#> Warning message:
#> In system("whoami", intern = TRUE) : running command 'whoami' had status 1
#> Running on host: packrat-restore-z5s57-f9z6b
#> Linux distribution: Ubuntu 22.04.2 LTS (jammy)
#> Running as user: uid=999 gid=999 groups=999
#> Connect version: 2023.05.0
#> LANG: en_US.UTF-8
#> Working directory: /opt/rstudio-connect/mnt/app
#> Using R 4.2.2
#> R.home(): /opt/R/4.2.2/lib/R
#> Using user agent string: 'RStudio R (4.2.2 x86_64-pc-linux-gnu x86_64 linux-gnu)' 
#> # Validating R library read / write permissions --------------------------------
#> Using R library for packrat bootstrap: /opt/rstudio-connect/mnt/R/ghcr.io_rstudio_content-pro__r4.2.2-py3.11.3-ubuntu2204/4.2.2
#> # Validating managed packrat installation --------------------------------------
#> Vendored packrat archive: /opt/rstudio-connect/ext/R/packrat_0.9.1_91ea7f537fb69ce5706114dd8f949fa5b0820efc.tar.gz
#> Vendored packrat SHA: 91ea7f537fb69ce5706114dd8f949fa5b0820efc
#> Managed packrat SHA:  91ea7f537fb69ce5706114dd8f949fa5b0820efc
#> Managed packrat version: 0.9.1
#> Managed packrat is up-to-date.
#> # Validating packrat cache read / write permissions ----------------------------
#> Using packrat cache directory: /opt/rstudio-connect/mnt/packrat/ghcr.io_rstudio_content-pro__r4.2.2-py3.11.3-ubuntu2204/4.2.2
#> Audited package hashes with local packrat installation.
#> Package repository URLs are being overridden with the following values:
#> Repository: CRAN = https://colorado.posit.co/rspm/all/latest
#> Repository: RSPM = https://colorado.posit.co/rspm/all/latest 
#> # Installing required R packages with `packrat::restore()` ---------------------
#> Installing R6 (2.5.1) ... 
#> Using cached R6.
#>  OK (symlinked cache)
#> Installing Rcpp (1.0.11) ... 
#> Using cached Rcpp.
#>  OK (symlinked cache)
#> Installing bit (4.0.5) ... 
#> Using cached bit.
#>  OK (symlinked cache)
#> Installing cli (3.6.1) ... 
#> Using cached cli.
#>  OK (symlinked cache)
#> Installing clipr (0.8.0) ... 
#> Using cached clipr.
#>  OK (symlinked cache)
#> Installing cpp11 (0.4.5) ... 
#> Using cached cpp11.
#>  OK (symlinked cache)
#> Installing crayon (1.5.2) ... 
#> Using cached crayon.
#>  OK (symlinked cache)
#> Installing curl (5.0.1) ... 
#> Using cached curl.
#>  OK (symlinked cache)
#> Installing digest (0.6.33) ... 
#> Using cached digest.
#>  OK (symlinked cache)
#> Installing fansi (1.0.4) ... 
#> Using cached fansi.
#>  OK (symlinked cache)
#> Installing fs (1.6.3) ... 
#> Using cached fs.
#>  OK (symlinked cache)
#> Installing generics (0.1.3) ... 
#> Using cached generics.
#>  OK (symlinked cache)
#> Installing glue (1.6.2) ... 
#> Using cached glue.
#>  OK (symlinked cache)
#> Installing jsonlite (1.8.7) ... 
#> Using cached jsonlite.
#>  OK (symlinked cache)
#> Installing magrittr (2.0.3) ... 
#> Using cached magrittr.
#>  OK (symlinked cache)
#> Installing mime (0.12) ... 
#> Using cached mime.
#>  OK (symlinked cache)
#> Installing pkgconfig (2.0.3) ... 
#> Using cached pkgconfig.
#>  OK (symlinked cache)
#> Installing prettyunits (1.1.1) ... 
#> Using cached prettyunits.
#>  OK (symlinked cache)
#> Installing rappdirs (0.3.3) ... 
#> Using cached rappdirs.
#>  OK (symlinked cache)
#> Installing rlang (1.1.1) ... 
#> Using cached rlang.
#>  OK (symlinked cache)
#> Installing sodium (1.2.1) ... 
#> Using cached sodium.
#>  OK (symlinked cache)
#> Installing stringi (1.7.12) ... 
#> Using cached stringi.
#>  OK (symlinked cache)
#> Installing swagger (3.33.1) ... 
#> Using cached swagger.
#>  OK (symlinked cache)
#> Installing sys (3.4.2) ... 
#> Using cached sys.
#>  OK (symlinked cache)
#> Installing utf8 (1.2.3) ... 
#> Using cached utf8.
#>  OK (symlinked cache)
#> Installing whisker (0.4.1) ... 
#> Using cached whisker.
#>  OK (symlinked cache)
#> Installing withr (2.5.0) ... 
#> Using cached withr.
#>  OK (symlinked cache)
#> Installing yaml (2.3.7) ... 
#> Using cached yaml.
#>  OK (symlinked cache)
#> Installing bit64 (4.0.5) ... 
#> Using cached bit64.
#>  OK (symlinked cache)
#> Installing tzdb (0.4.0) ... 
#> Using cached tzdb.
#>  OK (symlinked cache)
#> Installing rapidoc (8.4.3) ... 
#> Using cached rapidoc.
#>  OK (symlinked cache)
#> Installing webutils (1.1) ... 
#> Using cached webutils.
#>  OK (symlinked cache)
#> Installing ellipsis (0.3.2) ... 
#> Using cached ellipsis.
#>  OK (symlinked cache)
#> Installing later (1.3.1) ... 
#> Using cached later.
#>  OK (symlinked cache)
#> Installing lifecycle (1.0.3) ... 
#> Using cached lifecycle.
#>  OK (symlinked cache)
#> Installing lobstr (1.1.2) ... 
#> Using cached lobstr.
#>  OK (symlinked cache)
#> Installing askpass (1.1) ... 
#> Using cached askpass.
#>  OK (symlinked cache)
#> Installing promises (1.2.0.1) ... 
#> Using cached promises.
#>  OK (symlinked cache)
#> Installing vctrs (0.6.3) ... 
#> Using cached vctrs.
#>  OK (symlinked cache)
#> Installing openssl (2.1.0) ... 
#> Using cached openssl.
#>  OK (symlinked cache)
#> Installing httpuv (1.6.11) ... 
#> Using cached httpuv.
#>  OK (symlinked cache)
#> Installing hms (1.1.3) ... 
#> Using cached hms.
#>  OK (symlinked cache)
#> Installing pillar (1.9.0) ... 
#> Using cached pillar.
#>  OK (symlinked cache)
#> Installing purrr (1.0.1) ... 
#> Using cached purrr.
#>  OK (symlinked cache)
#> Installing tidyselect (1.2.0) ... 
#> Using cached tidyselect.
#>  OK (symlinked cache)
#> Installing httr (1.4.6) ... 
#> Using cached httr.
#>  OK (symlinked cache)
#> Installing plumber (1.2.1) ... 
#> Using cached plumber.
#>  OK (symlinked cache)
#> Installing progress (1.2.2) ... 
#> Using cached progress.
#>  OK (symlinked cache)
#> Installing tibble (3.2.1) ... 
#> Using cached tibble.
#>  OK (symlinked cache)
#> Installing bundle (0.1.0) ... 
#> Using cached bundle.
#>  OK (symlinked cache)
#> Installing butcher (0.3.2) ... 
#> Using cached butcher.
#>  OK (symlinked cache)
#> Installing cereal (0.1.0.9000) ... 
#> Using cached cereal.
#>  OK (symlinked cache)
#> Installing hardhat (1.3.0) ... 
#> Using cached hardhat.
#>  OK (symlinked cache)
#> Installing pins (1.2.0) ... 
#> Using cached pins.
#>  OK (symlinked cache)
#> Installing vroom (1.6.3) ... 
#> Using cached vroom.
#>  OK (symlinked cache)
#> Installing readr (2.1.4) ... 
#> Using cached readr.
#>  OK (symlinked cache)
#> Installing vetiver (0.2.2) ... 
#> Using cached vetiver.
#>  OK (symlinked cache)
#> Stopped session pings to http://service-f23cc8d4-d638-42cf-88ac-791eafbf43e3.rstudio-connect:50734
#> Launching Plumber API...
#> ── Deployment complete ─────────────────────────────────────────────────────────
#> ✔ Successfully deployed to <https://colorado.posit.co/rsc/mtcars-vetiver-example-api/>

Created on 2023-08-11 with reprex v2.0.2

You can see an example of this in the Posit Connect docs here as well; notice account being passed through.

If you think you have accounts that are not useful (like old ones), you can manage them with these functions from the rsconnect R package.