14 Pins
The pins
R package provides a way for R
users to easily share data using RStudio Connect. Your resources may be text
files (CSV, JSON, etc.), R objects (.Rds
, .Rda
, etc.) or any other format
you use to share data. Sharing data can be useful in many situations, for
example:
Multiple pieces of content require the same input data. Rather than copying that data, each piece of content references a single source of truth hosted on RStudio Connect.
Content depends on data or model objects that need to be regularly updated. Rather than redeploying the content each time the data changes, use a pinned resource and update only the data. The data update can occur using a scheduled R Markdown document. Your content will read the newest data on each run.
You need to share resources that aren’t structured for traditional tools like databases. For example, models saved as R objects aren’t easy to store in a database. Rather than using email or file systems to share data files, use RStudio Connect to host these resources as pins.
14.1 Deploying a Pin
14.1.1 Deploying a Pin from RStudio
To deploy a pin from RStudio, first follow the steps to link RStudio to Connect.
Once complete, you can deploy a pin using the package’s board_register
and
pin
functions:
board_register("rsconnect", server = "https://connect.example.com")
iris %>%
filter(Species == "Setosa") %>%
pin("s_iris", board = "rsconnect")
14.1.2 Deploying a Pin from R code
You may wish to deploy a pin from outside of RStudio. For example, you can write a R Markdown document that deploys a pin. That R Markdown document is deployed to RStudio Connect and run on a schedule. In this case, you must use an API key when you register the board. The code inside your R Markdown document might look like:
connectAPIKey <- Sys.getenv("CONNECT_API_KEY")
board_register("rsconnect",
server = "https://connect.example.com",
key = connectAPIKey)
iris %>%
filter(Species == "Setosa") %>%
pin("s_iris", board = "rsconnect")
This code obtains the API key from an environment variable before supplying
that key to board_register
. Section 5.3 contains
additional examples that use API keys from code.
14.2 Pin Settings
You can manage content settings for deployed pins just like you would for other content types. For example, you can manage access controls to pins to determine who should be able to view and utilize the resource. You can also add more information about your pin, and track the number of times the pin has been requested.
14.3 Using a Pin
Once a pin has been deployed, it is easy to share the pin with colleagues. You can either share the link to the pin in RStudio Connect, or colleagues can search for resources using the pin package within RStudio.
board_register("rsconnect", server = "https://connect.example.com")
get_pin("s_iris", board = "rsconnect")
If you want to access a pin with restricted access from other content deployed to RStudio Connect, such as a Shiny application, you will need to use an API key.
connectAPIKey <- Sys.getenv("CONNECT_API_KEY")
board_register("rsconnect",
server = "https://connect.example.com")
key = connectAPIKey)
get_pin("s_iris", board = "rsconnect")
Section 5.3 contains additional examples that use API keys from code.
Learn more about using pins on RStudio Connect.