How to Publish a Plumber API to Posit Connect
This guide used RStudio Version 1.3.959.
This guide walks you through creating a new Plumber API, and then publishing your document to Posit Connect.
Prerequisites
Before you begin, you must:
- Install R
- Install RStudio
- Have the public URL of the Connect server
- Have a valid Connect account that has been promoted to at least the Publisher role
- Connect your Posit Account
For more information about requesting permission to publish your content, please see the Publishing section of the User Guide.
As you walk through this guide, there might be additional steps that are required due to your unique environment. For example, you might need to install or update packages, restart R, etc. In many cases, Connect prompts you to complete the action that is required to continue with this guide. If you get stuck, please refer to the Related Documentation section or the Posit Connect Admin Guide.
Step 1. Create a new Plumber API
RStudio has a sample Plumber API that is available out of the box. For this guide, we are going to utilize the sample Plumber API. Everyone has access to it, and it allows us to focus on the task of publishing the Plumber API to Connect instead of manually creating the Plumber API from scratch. Let’s begin!
Open RStudio.
From the menu bar, select File > New File > Plumber API…. The New Plumber API window opens.
If you are prompted to install additional packages that are required, click Yes.
Give your new Plumber API a name and click Create. The script for your Plumber API opens in the editor.
Now, we should confirm that the Plumber API was successfully created. At the top right of the editor, click Run API.
If the Plumber API runs successfully, a new window displays.
Try it out
Now that you have successfully run your Plumber API in RStudio, you can try it out!
RStudio has the option to run your Plumber API in the built-in Viewer pane. Once your Plumber API displays in the Viewer pane, you can try out the default endpoints.
At the top of the editor, click the Run API drop-down menu, then select Run in Viewer Pane. Your Plumber API opens in the Viewer pane.
In the Viewer pane, scroll down and expand the
/plot
endpoint.Now, click Try it out.
Click Execute. The responses from your Plumber API opens.
Step 2. Publish your Plumber API to Connect
Before you execute this step, verify that you have connected your RStudio Account. The procedure is available in the Connect your Posit Account how to guide.
At the top of the editor, click Publish.
In the Publish to Server window, confirm that your account is shown in the Publish to Account section and click Publish.
- You can monitor the status of the deployment in the RStudio Deploy pane.
- If for any reason you would like to stop the deployment, you can simply click the Stop button located in the Deploy pane.
- Your newly deployed R Markdown document automatically opens in a new browser tab if the Launch browser check box is selected (it is selected by default).
- If it doesn’t automatically display, your app might have been blocked as a popup in your browser.
Step 3. View the Plumber API on Connect
Navigate back to the Connect server that you published your content to.
If applicable, log back into Connect.
To view the Content that you own, click the Options button.
In the Owners section, select Yours. Your Plumper API displays in the Content section.
To view your Plumber API, simply click the title of your Plumber API.
Your Plumber API displays in the Connect browser window.
Try it out
Now that you have successfully published your Plumber API to Connect, you can try it out!
Navigate to Connect and select your Plumber API.
For this example, expand the
/plot
endpoint.Now, click Try it out.
Click Execute.
The responses of your Plumber API display.