Skip to content

How to Publish a Jupyter Notebook to RStudio Connect#

This guide walks you through creating and publishing a new Jupyter Notebook and to RStudio Connect.

Prerequisites#

Before you begin, you must:

  • Have the public URL of the RStudio Connect server
  • Have a valid RStudio Connect account that has been promoted to at least the Publisher role
  • Have a working Anaconda/Miniconda Python installation
  • Have installed the following Python packages:
    • jupyter
    • matplotlib
    • pandas

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

Step 1. Install the Jupyter Notebook extension#

First, you need to install the rsconnect-jupyter package for the Jupyter Notebook that enables you to publish Jupyter Notebooks to RStudio Connect.

  • Open a new terminal window and run:
    Terminal
    pip install rsconnect_jupyter
    
  • Now, we need to enable the Jupyter Notebook extension:

    Terminal
    jupyter-nbextension install --sys-prefix --py rsconnect_jupyter
    jupyter-nbextension enable --sys-prefix --py rsconnect_jupyter
    jupyter-serverextension enable --sys-prefix --py rsconnect_jupyter
    

  • To verify that the installation was successful, run:

    Terminal
    jupyter notebook
    

    • If the Jupyter Notebook interface doesn't automatically display in your browser, then copy and paste the URL(s) provided in the output of your terminal.

Step 2. Create a new Jupyter Notebook#

We are going to create a sample notebook that we will publish to RStudio Connect.

  • Open your browser window displaying the main Jupyter Notebook interface, if applicable.
  • At the top of the page, click New and select Python 3. An image of the
  • Click the title field. The title field is located at the top of the page and to
  the right of the jupyter logo
  • In the Rename Notebook window, give your notebook a name and click Rename. The Rename Notebook window is shown and it also highlights
  the Rename button

  • In the cell, copy and paste the following:

    import pandas as pd
    dF = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data", names=["sl", "sw", "pl", "pw", "class"])
    dF.head()
    
  • Press Shift + Enter.

       The first five rows of the dataset display. An image displaying the first five rows of the dataset

  • In the new cell, type:

    import matplotlib
    %matplotlib inline
    dF.plot(x="sl", y="sw", kind="scatter")
    
  • Press Shift + Enter.

   A scatter plot displays. An image displaying the example scatter plot

Step 3. Connect Jupyter Notebook to RStudio Connect#

Note

This is a one-time configuration step that is required to publish Jupyter Notebooks to RStudio Connect.

To publish our notebook to RStudio Connect, we need to generate an API Key.

  • Navigate and log into RStudio Connect.
  • Click your username or profile icon. The icon is located in the upper-right corner of your
    browser page on the RStudio Connect navigation/menu bar
  • Click API Keys. Once you click your profile, a Profile menu displays.
    The API Keys option is located under the first option, which is
  • Click + New API Key. The NEW API Key button is located on the right
    side of the page
  • Enter a name for your API Key and click OK. The OK button is on the lower-right side of the window
  • To copy your API Key, click Copy. The Copy button is located under the API Key

Step 4. Publish to RStudio Connect#

  • Return to your Jupyter Notebook that you wish to publish.
  • Click Publish and select Publish to RStudio Connect.

The button is located on the right side of the menu-button bar

  • Add your RStudio Connect Server:
  1. In the Server Address field, enter the public URL used to access RStudio Connect.
  2. In the API Key field, paste the API Key that you generated in RStudio Connect.
  3. In the Server Name field, type a name for your server.
  4. If you require an option other than the default Use System TLS Certificates option, then select one of the Secure Connection Settings.
  5. Click Add Server.

This is a screen capture of the Add RStudio Connect Server
  window

  • In the Publish to RStudio Connect window, do the following:
  1. In the Publish to field, confirm that your RStudio Connect Server Address (the public URL) is correct.
  2. Optionally, update the title of your Jupyter Notebook that will be displayed in RStudio Connect.
  3. Leave the default option for Publish Source Code selected.
  4. Click Publish.

This is an image of the Publish
  to RStudio Connect menu

  • Select the radio button for your notebook and click Next. The button is located on the left side of the
    page and the Next button is located on the lower-right side of the window
  • Click Publish. The button is located on the
    lower-right side of the window

  • At the top of the interface, click the Successfully published content button. The button is on the right-side of the menu bar

An RStudio Connect browser window opens and displays your published Jupyter Notebook.

Info

Your Jupyter Notebook is running Python code because we have reconstructed the Python environment in RStudio Connect.

Here is an example of a Jupyter Notebook that was published to RStudio Connect:

A screen capture of the notebook that was
published to RStudio Connect

Bonus Content

We also have a Video Tutorial available.