I've made an R package (lets call it {myapi}) that defines a plumber API. I've made a separate repo (lets call it {myapi-deploy}) that handles the deployment of the plumber API to Posit Connect. I am having trouble hitting endpoints that use a pooled database connection (defined with pool::dbPool()). I can successfully call endpoints that don't require a pool object. I can make a successful database connection on Posit Connect outside of a plumber deployment context.
library(rsconnect)
deployAPI(
"dir",
account = "x",
server = "x"
)
When I attempt to use an endpoint that depends on the pool object, I get an error like:
{
"error": "500 - Internal server error",
"message": "Error in dplyr::tbl(pool, \"x\"): object 'pool' not found\n"
}
When I run dir/entrypoint.R in full and use plumber::pr_run() to deploy locally, the pool object is initiated and the API calls work. How can I ensure that the pool object is initiated correctly at runtime on Posit Connect when deploying with rsconnect::deployAPI()?
Bruno was on the right track: the pool variable can be found during local development but not once deployed because of differences in the search paths (this is the explanation I got from one of the plumber maintainers).
Defining this function that super-assigns the pool object: