Posit Connect 2023.03.0

Posit Connect now supports Voilà and Jupyter Widgets for adding interactive elements to a Jupyter Notebook.
2023-03-30
Text: "Product Release, Posit Connect 2023.03.0 Voila and Jupyter Widgets." Posit Connect logo. On the right, a screenshot of a Jupyter notebook with an interactive plot published on Connect.

Posit Connect now supports Voilà and Jupyter Widgets in the Standard license and above. This blog describes how to add interactive elements to a Jupyter Notebook without refactoring it into an application. 

Data science projects require different communication strategies depending on the engagement level and data literacy of your audience. These goals inform the type of deliverable you produce and influence the success or impact of your project. Ultimately the choice is up to you, but it pays to know a few content frameworks in order to balance simplicity with interactivity. The good news is that Connect makes it easy to publish and iterate quickly, so you can change project deliverables over time or based on feedback from stakeholders. 

 

Posit Connect Supported Python Content Types in 2023

Content Type Framework
Documents & Notebooks Jupyter Notebooks
Quarto
Interactive Notebooks Jupyter Notebooks with Voila and Jupyter Widgets
Interactive Applications Dash
Streamlit
Bokeh
Shiny
WSGI Frameworks Flask
ASGI Frameworks FastAPI (also Quart, Falcon, and Sanic)

Interactive Jupyter Notebooks

Jupyter notebooks published in Connect can now use Jupyter Widgets ipywidgets for interactivity via the Voilà package. Interactive mode runs the notebook each time a user visits it and maintains a live Jupyter kernel to support widget components. Connect Publishers can find a new Jump Start example in the “Publish” dropdown located in the content dashboard. 

To get started, upgrade your preferred Posit Connect publishing client:

  • If you use the Jupyter Notebook push-button publishing plugin, install rsconnect-jupyter 1.8.0. 
  • If you use the CLI to publish python content, upgrade to rsconnect-python 1.15.0.

Once both Posit Connect and your publishing client are updated, you’ll be able to deploy Voilà notebooks. For more information, reference the Posit Connect: User Guide.

 

A Simple Example

The python Palmer Penguins dataset README has a nice seaborn boxplot example which shows penguin body mass visualized by species and island.

Say you wanted to present the visualization for each of the other penguin body measurements. Instead of replicating the plot or refactoring the entire notebook to create an application, turn the boxplot into a function and add a dropdown selection widget. The live Jupyter kernel allows users to interact with code once the notebook is deployed to Connect.

Make simple plots interactive with Jupyter Widgets:

  1. Import ipywidgets
  2. Turn your visualization into a function
  3. Define your input selection widget (seen here with the interact decorator syntax)
  4. Test the widget locally
  5. Publish to Connect with Voilà interactive mode

A plot in a Jupyter Notebook pointing to its corresponding code

import ipywidgets as widgets
opts = ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"]

@widgets.interact(attribute=opts)
def penguins_box(attribute = "body_mass_g"):
 g = sns.boxplot(x = 'island',
                 y = attribute,
                 hue = 'species',
                 data = penguins,
                 palette=['#FF8C00','#159090','#A034F0'],
                 linewidth=0.3)

 

Publishing

Once you’ve added an interactive element to the notebook, use the voila deployment option to publish to Connect. 

  • Interactive Notebook Publishing: rsconnect deploy voila -n my_server penguins.ipynb
  • Standard Notebook Publishing: rsconnect deploy notebook -n my_server penguins.ipynb

Previously published standard notebooks need to be re-deployed to a new content location on Connect because the app_mode for an existing content item cannot be updated once it has been established.

To force a new deployment with the CLI, use the --new flag like this: rsconnect deploy voila -n my_server penguins.ipynb –new.

A GIF showing an interactive plot on Posit Connect

 

Specifying a Theme

You can customize a notebook theme by including a voila.json file in the deployment directory. See the Voilà documentation for details.

A Voila configuration JSON file and the corresponding notebook  with the Jupyterlab Miami Theme

When using a custom JupyterLab theme, include the theme package in your requirements.txt file. This ensures that Posit Connect installs it in the virtual environment where your notebook will be run.

 

Upgrade Posit Connect

Before upgrading, please review the full release notes

 

Notes for Administrators

  • Posit Connect now serves a default robots.txt that disallows all crawling. Admins can specify a custom robots.txt using the Branding.Robots configuration option. Configuration Reference
  • PostgreSQL 15 is now a supported database provider. The minimum supported PostgreSQL version is 11.0. Admin Guide Reference
  • When permitted by the system, the sandbox used to run content processes now includes a user namespace for additional process isolation. Admin Guide Reference

Upgrading Posit Connect typically requires less than five minutes.

If you are upgrading from a version earlier than the January 2023 edition, be sure to consult the release notes for changes in intermediate releases that may not be mentioned in this blog post.

To perform a Posit Connect upgrade, download and run the installation script. The script installs a new version of Connect on top of the earlier one. Existing configuration settings are respected. 

Standard upgrade documentation can be found here.