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:

For more information about requesting permission to publish your content, please see the Publishing section of the User Guide.

Note

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.

    RStudio New File options screen capture

  • 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.

    New Plumber API window

  • Now, we should confirm that the Plumber API was successfully created. At the top right of the editor, click Run API.

    Run API button screen capture

  • If the Plumber API runs successfully, a new window displays.

    Swagger window displaying the Plumber Example API

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.

    Screen capture of the Run API menu displayed with the Run in Viewer Pane option selected

  • In the Viewer pane, scroll down and expand the /plot endpoint.

    Screen capture of the Viewer pane

  • Now, click Try it out.

    The Parameters section features the Try it out button

  • Click Execute. The responses from your Plumber API opens.

    The Execute button displays after you click Try it out and is located in the Parameters section

    A screen capture of the Plumber API responses

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.

    Example of the Publish button

  • In the Publish to Server window, confirm that your account is shown in the Publish to Account section and click Publish.

    Screen capture of the Publish to Server window

User tips
  • 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.

    The Options button is located on the upper-right side of the window

  • In the Owners section, select Yours. Your Plumper API displays in the Content section.

    Image of the Yours radio button selected

  • To view your Plumber API, simply click the title of your Plumber API.

    Image of Content being selected

  • Your Plumber API displays in the Connect browser window.

    Screen capture of Plumber API displaying in a browser

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.

    The Try it out button is located in the Parameters section

  • Click Execute.

    The Execute button displaying in the Parameters section once you click Try it out

  • The responses of your Plumber API display.

    A screen capture of the Plumber API responses