Leveraging Pins with Posit Connect
videoimage: thumbnail.jpg
Transcript#
This transcript was generated automatically and may contain errors.
In this video, we're going to go through the process of pinning a dataset to Posit Connect using the pins package. So over here on the left hand side, we have a pins demo R script, and we're going to walk through all these steps.
The first thing we'll do is install the pins package and then load the pins package into our environment. So I'll highlight these lines of code and I'll hit run.
Defining a board
Now in order to use pins, you first have to define a board. And so for this workflow, we're going to use Posit Connect as our board. The first thing we need to do is register our board. So the easiest way to do that is to go to tools, global options and select publishing. So the top of my screen, I'll go to tools. All the way at the bottom, we have global options. And towards the bottom, we have publishing.
Unfortunately, I do not have any Posit Connect instances registered. So we're going to connect to a new one. So I'll click connect here in the top right. We're going to choose Posit Connect. And here is where you want to provide the URL of your Connect instance. I'll select next. And we get this pop up menu to connect to R. That all looks good. We'll hit connect.
I can close out of this and then connect account. All right, so we're now connected to our instance of Posit Connect. I can apply these changes and hit OK.
All right, so now that we've registered our Posit Connect instance, we first need to define this Connect instance as our board. And to do that, we're going to use the board connect function from the pins package. And we're going to call this my board. So let me run this line of code.
And you can see at the bottom, connecting to Posit Connect. And there's the URL for my Connect instance.
Pinning a dataset
And now we can actually pin the data set. So in this example, we're going to use the pin write function from the pins package. And we're going to pin the mtcars data set. We're going to pin it to my Connect instance, which we registered in the previous step. We're going to call it mtcars data set. You can call it whatever you want. And we're going to save this pin as a CSV file. So let's highlight all this. We'll hit Run.
At the bottom of the screen, you can see writing to pin Ryan. That's me, mtcars data set. And now we can actually switch over to Posit Connect. And I can show you what a pinned data set looks like.
So here's the pinned data set, the mtcars data set. You can actually get a snippet of what the data set looks like right here. And you can actually scroll across. But most importantly, with pins, you want to know how to pull this pin into your own workflow, into your own script, whatever you're developing. And it provides the code on how to do that.
Reading a pinned dataset
So we're going to take this code. We're going to come back to Posit Workbench, the RStudio IDE within Posit Workbench here. And we're going to read in that pin data set. So we'll use the pin read function from the pins package. We're going to, again, let pins know that this is the board I want to use. And I'm going to pull in this pin. That's my name, the mtcars data set. So let's run that.
And then you'll see here in my console, here is the printed out pinned mtcars data set. And that is how you pin a data set to Posit Connect.
