Learn R Programming

⚠️There's a newer version (0.10.0) of this package.Take me there.

connectapi

This package provides an R client for the Posit 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.

Disclaimer

Because many of these functions are experimental, it is advisable to be cautious about (1) upgrading the package, (2) upgrading Posit Connect when you care about the reproducibility of workflows that use connectapi. As a result, we would advise:

  • managing package versions with renv
  • test your dependent content before and after upgrading Posit Connect

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 Posit Connect Server API is helpful and what additional endpoints would be useful!!

Installation

To install from CRAN:

install.packages("connectapi")

To install the development version:

remotes::install_github('rstudio/connectapi')

Client

To create a client:

library(connectapi)
client <- connect(
  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)
client <- connect()

Getting Started

Once a client is defined, you can use it to interact with Posit Connect.

Exploring Data

You can use the get_ methods to retrieve data from the Posit Connect server.

library(connectapi)
client <- connect()

# get data
users <- get_users(client)
groups <- get_groups(client)
usage_shiny <- get_usage_shiny(client)
usage_static <- get_usage_static(client)
some_content <- get_content(client)

# get all content
all_content <- get_content(client, limit = Inf)

Deployment

The rsconnect package is usually used for deploying content to Connect. However, if you want to use programmatic deployment with the Posit Connect Server API, then these connectapi helpers should be useful!

library(connectapi)
client <- connect()

# deploying content
# NOTE: a `manifest.json` should already exist from `rsconnect::writeManifest()`

bundle <- bundle_dir("./path/to/directory")
content <- client %>% 
  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"

content$update(access_type = "all")
  
# edit another piece of content

client %>%
  content_item("the-content-guid") %>%
  set_vanity_url("/another-awesome-app")
  
# migrate content to another server

client_prod <- connect(
  server = "prod.example.com",
  api_key = "my-secret-key"
)

prod_bnd <- client %>%
  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
client_prod %>% browse_dashboard()
client_prod %>% browse_solo()

# open a browser to the docs
client_prod %>% browse_api_docs()

Troubleshooting and FAQ

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 Posit Connect cluster to do the operation in question

Constant warning about version numbers

This warning is intentionally chatty. While version number mismatches between Posit Connect and connectapi can be benign, we want you to be clear that connectapi is tightly coupled to a version of Posit Connect (because Posit Connect’s APIs change over time).

We strive to:

  • track the latest version of the Posit Connect API
  • add new features as they come available and have demand
  • maintain backwards compatibility

These priorities are sometimes at odds, and sometimes they create inconsistencies between versions as a result. To mitigate this, we recommend:

  • Track the version of connectapi in use for your applications by using renv
  • Test high value content that uses connectapi before updating connectapi or Posit Connect
  • Update Posit Connect to the latest version first when an update to connectapi is needed

Error - Need to update Posit 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 Posit Connect.

If you get this error message, our recommendation would be:

  • Look at NEWS.md to find the moment the change was introduced
  • Downgrade connectapi to the previous version of the package
  • (Advanced) Use the “blame” feature on GitHub to track commits and find out when the error was introduced

Please feel free to open an Issue if you think there is a bug, or ask a free-form question on Posit Community

Other ideas for FAQs or Common Issues?

Please submit a PR! We would love to have your contribution!

Code of Conduct

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.

Copy Link

Version

Install

install.packages('connectapi')

Monthly Downloads

1,244

Version

0.1.3.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Cole Arendt

Last Published

February 2nd, 2023

Functions in connectapi (0.1.3.1)

Bundle

Bundle
Vanity

Vanity
VariantTask

VariantTask
Task

Task
Environment

Environment
ContentTask

ContentTask
PositConnect

Class representing a Connect API client
Variant

Variant
Content

Content
VariantSchedule

VariantSchedule
audit_vanity_urls

Audit Vanity URLs
browse_solo

Browse
bundle_dir

Define a bundle from a Directory
acl_add_user

ACL Add Users or Groups
bundle_path

Define a bundle from a path (a path directly to a tar.gz file)
cache_apps

Get information on all apps for a server
content_item

Get Content Item
bundle_static

Define a bundle from a static file (or files)
content_list_by_tag

Content List
audit_r_versions

Audit R Versions
content_delete

Delete Content
delete_vanity_url

Delete the Vanity URL
connectapi-package

connectapi: Utilities for Interacting with the 'Posit Connect' Server API
deploy

Deploy a bundle
collect

Collect function
get_acl_user

Get ACL Details
get_environment

Manage Environment Variables
connect

Create a connection to Posit Connect
audit_runas

Audit Run As Settings
content_update

Update Content
create_random_name

Create Random Name
download_bundle

Download a Bundle from Deployed Connect Content
deploy_repo

Deploy a Git Repository
get_usage_static

Get usage information from deployed static content
get_users

Get user information from the Posit Connect server
content_list_with_permissions

Get Content List with Permissions
audit_access_open

Audit Access Controls
content_title

Get Content Title
get_timezones

Get TimeZones
groups_create_remote

Create a Remote Group
git

Git Repository Helpers
get_content

Get information about content on the Posit Connect server
get_usage_shiny

Get usage information for deployed shiny applications
get_content_old

Get information about content on the Posit Connect server
poll_task

Poll Task
promote

Promote content from one Connect server to another
%>%

Pipe operator
permissions

Content permissions
dashboard_url_chr

Build a Dashboard URL from Character Vectors
dashboard_url

Build a Dashboard URL from a Content Item
get_group_members

Get users within a specific group
get_vanity_url

Get the Vanity URL
get_variant_schedule

Get a Variant Schedule
get_tags

Get all Tags on the server
get_groups

Get group information from the Posit Connect server
tbl_connect

Connect Tibble
set_run_as

Set RunAs User
set_schedule

Set a Schedule
get_jobs

Get Jobs
page_cursor

Paging
get_variant_renderings

Render a Variant
set_image_path

Set the Content Image
get_variants

Get Variant
vec_cast.fs_bytes

Cast to fs_bytes
set_vanity_url

Set the Vanity URL
swap_vanity_url

Swap the Vanity URL
get_audit_logs

Get Audit Logs from Posit Connect Server
user_guid_from_username

User
get_procs

Get Real-Time Process Data
get_bundles

Get Bundles
users_create_remote

Create a Remote User
wait_for_process

Wait for a Process to Complete
verify_content_name

Verify Content Name
get_image

Get the Content Image