Code Monkey home page Code Monkey logo

connectapi's Introduction

Lifecycle: maturing CRAN status Codecov test coverage R build status

connectapi

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.

Disclaimer

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:

  • managing package versions with renv
  • test your dependent content before and after upgrading RStudio 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 RStudio Connect Server API is helpful and what additional endpoints would be useful!!

Installation

To install the development version:

remotes::install_github('rstudio/connectapi')

Client

To create a client:

library(connectapi)
client <- connect(
  host = '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 RStudio Connect.

Exploring Data

You can use the get_ methods to retrieve data from the RStudio 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, n = Inf)

Deployment

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)
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")
  
# 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(
  host = "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()

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.