Jupyter Notebook
You can deploy a Jupyter Notebook to Posit Connect in two ways:
- With source code: Connect runs the notebook on the server, so you can rerun it on request or on a schedule. Connect builds the notebook’s Python environment from a
requirements.txtfile. - As a static snapshot: The Posit CLI runs the notebook on your computer and publishes only the rendered HTML. Connect cannot rerun a snapshot.
Deploying a notebook with source code
Here’s an example command that deploys a Jupyter Notebook to Posit Connect using a server saved as myServer:
Terminal
posit connect deploy notebook -n myServer my-notebook.ipynbReplace myServer with the nickname of your saved server, or omit -n myServer to deploy to your default server. posit connect login saves the server under its hostname and makes it the default.
Package dependencies
The deploy command reads the notebook’s package dependencies from a requirements.txt file in the same directory as the notebook file. If the file does not exist, the command stops with an error. Connect reconstructs the Python environment using the specified package list.
To create the file, export your project’s locked dependencies:
Terminal
uv export --no-dev --no-emit-project --no-hashes -o requirements.txtSee package dependencies for other options.
Including extra files
You can include extra files in the deployment bundle to make them available when your notebook is run by the Connect server. Specify them on the command line after the notebook file:
Terminal
posit connect deploy notebook my-notebook.ipynb data.csvDeploying a static snapshot
Use the --static option to run the notebook on your computer and publish the rendered HTML:
Terminal
posit connect deploy notebook --static my-notebook.ipynbThe Posit CLI runs the notebook with nbconvert in your project’s Python environment. That environment needs nbconvert, ipykernel, and every package that the notebook imports. Add nbconvert and ipykernel to your project as development dependencies:
Terminal
uv add --dev nbconvert ipykernelThe Posit CLI uses the activated virtual environment, or a .venv directory in the notebook’s directory or one of its parents. To run the notebook with a different Python, specify its path with the --python option.
The snapshot contains only the rendered HTML, so a static deployment does not need a requirements.txt file. The Posit CLI does not upload extra files that you list on the command line, although the notebook can read local files while it runs. You cannot create a manifest for a static snapshot.
Hiding input code cells
You can hide input code cells in notebooks deployed with source code and in static snapshots. There are two options:
Hide all input code cells
Deploy the notebook with the --hide-all-input option to hide all input code cells:
Terminal
posit connect deploy notebook my-notebook.ipynb --hide-all-inputHide only selected input code cells
To hide only the tagged cells, first enable Tags in the View > Cell Toolbar menu:
Once enabled, tag each cell where you want to hide the input code. You must name the tag hide_input:
Terminal
posit connect deploy notebook my-notebook.ipynb --hide-tagged-inputInteractive notebooks with Voilà
By default, Connect renders Jupyter notebooks into HTML documents. If your notebook includes interactive widgets (ipywidgets), deploy using Voilà mode to present the notebook interactively using Voilà. For more information, see the Interactive Documents section.
Supported content
Notebooks that use ipywidgets for interactivity can be deployed to Connect. Other kinds of active content, such as embedded applications and APIs, are not supported.
When you are ready to deploy an application that you developed in a notebook, first export the notebook from Jupyter into a separate .py file using the File > Export Notebook As… > Executable Script menu item. Then deploy the file using the Posit CLI.
Deploying
To deploy to Connect:
Terminal
posit connect deploy voila my-notebook.ipynbYou can also deploy a directory containing notebooks in Voilà mode. Visitors can see a list of notebooks and select which one to open.
Terminal
posit connect deploy voila --multi-notebook ./Theming and customization
You can customize your Voila deployment by including a voila.json file in your deployment directory. See the voilà documentation for details.
If you use a custom JupyterLab theme with Voilà as described in the Voilà documentation, add the theme package to your project and export requirements.txt again, so that Connect installs the theme in the environment where your notebook runs:
Terminal
uv add <theme-package>
uv export --no-dev --no-emit-project --no-hashes -o requirements.txtDon’t edit requirements.txt by hand, because the next export overwrites your changes.
Jupyter kernels
Voilà automatically spawns a Jupyter kernel when a user visits a deployed Voilà notebook. Kernel processes are terminated when the user sessions ends (e.g., by closing the browser tab). When the user visits the notebook again, Voilà starts a new session with a new kernel.
The kernel preheating option in Voilà enables you to start up one or more Jupyter kernels and execute initialization code before users visit your deployed notebook. Connect can spawn multiple processes to serve user requests, based on the settings in the Runtime tab. Each worker process has its own set of preheated kernels.
Troubleshooting
If there are problems executing code in an interactive notebook, Voilà suggests using the --debug flag to show details about the error. You can enable Voilà debugging in Connect using the Environment Variables panel. Defining an environment variable named DEBUG with any non-empty value enables debugging.
Creating a manifest for future deployment
You can create a manifest.json file for a Jupyter Notebook with source code, then use that manifest in a later deployment. Use the write-manifest command to do this.
The write-manifest command reads the notebook’s package dependencies from a requirements.txt file in the same directory and stops with an error if the file does not exist. See package dependencies to create one.
Here is an example of the write-manifest command:
Terminal
posit connect write-manifest notebook my-notebook.ipynb
