This package provides an R client for the RStudio Connect Server
API as well as helpful functions that utilize the client. The
package is based on the rsconnnect
package, but is publicly
exported to be easier to use, is extensible via an R6 class, and is
separated from the rsconnect
package for easier support and
maintenance.
Because many of these functions are experimental, it is advisable to
be cautious about (1) upgrading the package, (2) upgrading RStudio
Connect when you care about the reproducibility of workflows that use
connectapi
. As a result, we would advise:
renv
Please pay careful attention to the lifecycle badges of the various functions and warnings present when you are using experimental features.
Also, please share feedback!! We love hearing how the RStudio Connect Server API is helpful and what additional endpoints would be useful!!
To install from CRAN:
install.packages("connectapi")
To install the development version:
::install_github('rstudio/connectapi') remotes
To create a client:
library(connectapi)
<- connect(
client server = 'https://connect.example.com',
api_key = '<SUPER SECRET API KEY>'
)
You can also define the following environment variables (in a
.Renviron
file, for instance):
CONNECT_SERVER = https://connect.example.com
CONNECT_API_KEY = my-secret-api-key
These environment variable values will be used automatically if defined in your R session.
library(connectapi)
<- connect() client
Once a client is defined, you can use it to interact with RStudio Connect.
You can use the get_
methods to retrieve data from the
RStudio Connect server.
library(connectapi)
<- connect()
client
# get data
<- get_users(client)
users <- get_groups(client)
groups <- get_usage_shiny(client)
usage_shiny <- get_usage_static(client)
usage_static <- get_content(client)
some_content
# get all content
<- get_content(client, limit = Inf) all_content
The rsconnect
package is usually used for deploying
content to Connect. However, if you want to use programmatic deployment
with the RStudio Connect Server API, then these connectapi
helpers should be useful!
library(connectapi)
<- connect()
client
# deploying content
# NOTE: a `manifest.json` should already exist from `rsconnect::writeManifest()`
<- bundle_dir("./path/to/directory")
bundle <- client %>%
content deploy(bundle, name = "my-app-name") %>%
poll_task()
# set an image for content
%>%
content set_image_path("./my/local/image.png")
%>%
content set_image_url("http://url.example.com/image.png")
# set image and a vanity URL
%>%
content set_image_path("./my/local/image.png") %>%
set_vanity_url("/my-awesome-app")
# change access_type to "anyone"
$update(access_type = "all")
content
# edit another piece of content
%>%
client content_item("the-content-guid") %>%
set_vanity_url("/another-awesome-app")
# migrate content to another server
<- connect(
client_prod server = "prod.example.com",
api_key = "my-secret-key"
)
<- client %>%
prod_bnd content_item("the-guid-to-promote") %>%
download_bundle()
%>%
client_prod deploy(prod_bnd, title = "Now in Production") %>%
set_vanity_url("/my-app")
# open a browser to the content item
%>% browse_dashboard()
client_prod %>% browse_solo()
client_prod
# open a browser to the docs
%>% browse_api_docs() client_prod
Access Denied Errors?
This is likely due to either (1) Connect$server
or
Connect$api_key
being defined improperly or (2) you do not
have access to the RStudio Connect cluster to do the operation in
question
Constant warning about version numbers
This warning is intentionally chatty. While version number mismatches
between RStudio Connect and connectapi
can be benign, we
want you to be clear that connectapi
is tightly coupled to
a version of RStudio Connect (because RStudio Connect’s APIs change over
time).
We strive to:
These priorities are sometimes at odds, and sometimes they create inconsistencies between versions as a result. To mitigate this, we recommend:
connectapi
in use for your
applications by using renv
connectapi
before
updating connectapi
or RStudio Connectconnectapi
is neededError - Need to update RStudio Connect
As a helpful clarification for users, we have added error messages to API requests when the version implemented in the package specifically introduces a backwards incompatible dependency on older versions of RStudio Connect.
If you get this error message, our recommendation would be:
NEWS.md
to find the
moment the change was introducedconnectapi
to the previous version of the
packagePlease feel free to open an Issue if you think there is a bug, or ask a free-form question on RStudio Community
Other ideas for FAQs or Common Issues?
Please submit a PR! We would love to have your contribution!
Please note that the connectapi project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.