How to Publish a Jupyter Notebook to Connect
This guide walks you through creating and publishing a new Jupyter Notebook to Posit Connect.
Prerequisites
Before you begin, you must:
- Have a compatible version of Python installed on the Connect Server
- Have the public URL of the Connect server
- Have a valid Connect account that has been assigned to at least the publisher role
- Have a working Python installation on the client
- Have installed the following Python packages:
jupyter
matplotlib
pandas
For more information about requesting permission to publish your content, see the Publishing section of the User Guide.
Step 1. Install the Jupyter Notebook extension
First, install the rsconnect-jupyter
package that enables you to publish Jupyter notebooks to Connect.
Depending on your environment, root
permissions are usually required for system-wide installations which might be necessary to install the rsconnect-jupyter
extension. For example, the --sys-prefix
flag needs write permissions to the Python installation path.
To do this, the commands might need to be run as root
or prefixed with sudo
. For example:
sudo pip install rsconnect_jupyter
Open a new terminal window and run:
Terminal
pip install rsconnect_jupyter
Now, you need to enable the Jupyter Notebook extension:
Terminal
-nbextension install --sys-prefix --py rsconnect_jupyter jupyter-nbextension enable --sys-prefix --py rsconnect_jupyter jupyter-serverextension enable --sys-prefix --py rsconnect_jupyter 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
Follow these steps to create a sample notebook to publish to Connect.
Open your browser window displaying the main Jupyter Notebook interface, if applicable.
At the top of the page, click New, then select Python 3.
Click the title field.
In the Rename Notebook window, give your notebook a name, then click Rename.
In the cell, copy and paste the following:
import pandas as pd = pd.read_csv( dF "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data", =["sl", "sw", "pl", "pw", "class"]) names dF.head()
Press Shift + Enter. The first five rows of the dataset display.
In the new cell, type:
import matplotlib %matplotlib inline ="sl", y="sw", kind="scatter") dF.plot(x
Press Shift + Enter. A scatter plot displays.
Step 4. Publish to Connect
Return to your Jupyter Notebook that you wish to publish.
Click Publish, then select Publish to Connect.
Add your Connect Server:
In the Server Address field, enter the public URL used to access Connect.
In the API Key field, paste the API Key that you generated in Connect.
In the Server Name field, type a name for your server.
If you require an option other than the default Use System TLS Certificates option, then select one of the Secure Connection Settings.
Click Add Server.
In the Publish to Connect window, do the following:
In the Publish to field, confirm that your Connect Server Address (the public URL) is correct.
Optionally, update the title of your Jupyter Notebook that will display in Connect.
Leave the default option for Publish Source Code selected.
Click Publish.
Select the radio button for your notebook and click Next.
Click Publish.
At the top of the interface, click the Successfully published content button.
A Connect browser window opens and displays your published Jupyter Notebook.
Your Jupyter Notebook is running Python code because the Python environment is reconstructed in Connect.
Here is an example of a Jupyter Notebook that was published to Connect: