Jupyter Notebooks
Using the rsconnect CLI#
Here's an example command that deploys a Jupyter notebook to Posit Connect,
assuming that you set up a server named myServer
when configuring your account:
rsconnect deploy notebook -n myServer my-notebook.ipynb
Notebook Deployment Options#
There are a variety of options available to you when deploying a Jupyter notebook to Posit Connect.
Including Extra Files#
You can include extra files in the deployment bundle to make them available when your notebook is run by the Posit Connect server. Just specify them on the command line after the notebook file:
rsconnect deploy notebook my-notebook.ipynb data.csv
Package Dependencies#
If a requirements.txt
file exists in the same directory as the notebook file, it will
be included in the bundle. It must specify the package dependencies needed to execute
the notebook. Posit Connect will reconstruct the Python environment using the
specified package list.
If there is no requirements.txt
file or the --force-generate
option is specified,
the package dependencies will be determined from the current Python environment, or
from an alternative Python executable specified via the --python
option or via the
RETICULATE_PYTHON
environment variable:
rsconnect deploy notebook --python /path/to/python my-notebook.ipynb
You can see the packages list that will be included by running pip list --format=freeze
yourself,
ensuring that you use the same Python that you use to run your Jupyter Notebook:
/path/to/python -m pip list --format=freeze
Static (Snapshot) Deployment#
By default, rsconnect
deploys the original notebook with all its source code. This
enables the Posit Connect server to re-run the notebook upon request or on a schedule.
If you just want to publish an HTML snapshot of the notebook, you can use the --static
option. This will cause rsconnect
to execute your notebook locally to produce the HTML
file, then publish the HTML file to the Posit Connect server:
rsconnect deploy notebook --static my-notebook.ipynb
Creating a Manifest for Future Deployment#
You can create a manifest.json
file for a Jupyter Notebook, then use that manifest
in a later deployment. Use the write-manifest
command to do this.
The write-manifest
command will also create a requirements.txt
file, if it does
not already exist or the --force-generate
option is specified. It will contain the
package dependencies from the current Python environment, or from an alternative
Python executable specified in the --python
option or via the RETICULATE_PYTHON
environment variable.
Here is an example of the write-manifest
command:
rsconnect write-manifest notebook my-notebook.ipynb
Note
Manifests for static (pre-rendered) notebooks cannot be created.