Skip to content

Jupyter Notebook#

Jupyter Notebooks can be deployed to RStudio Connect with the use of the rsconnect-jupyter plugin or the rsconnect-python Command Line Interface. See the Publishing Jupyter Notebooks Section to learn how to publish Jupyter Notebooks.

Jupyter Notebooks that are published with source code can be scheduled to execute on a regular basis on RStudio Connect. A full description of all scheduling features is available in the Scheduling chapter.

You may also view past renderings of Jupyter Notebooks that were published with source code. The Report History chapter has more details.

Hiding Input Code Cells#

There are two options for hiding input code cells in Jupyter Notebooks published to RStudio Connect:

  • Hide all input code cells
  • Hide only selected input code cells

Hiding input code cells can be useful when preparing notebooks for audiences where a cleaner or less code-heavy presentation would be more appreciated.

Examples of input code cells shown vs. hidden

Note

The example images below show the "Publish with Source Code" option selected. This is not a requirement for hiding input code cells. You may choose to publish notebooks with or without source code.

Hide All Input Code Cells#

Publishing Plugin Method#

To publish a Jupyter notebook where all input code cells are hidden, select Hide all input code cells in the publishing plugin dialog.

Publish dialog selection for hiding all input code cells

Note

The publishing plugin can also be used to generate a manifest for git-backed publishing. Learn more here.

CLI Method: rsconnect-python#

When publishing a Jupyter notebook with the rsconnect-python CLI, include the --hide-all-input flag to hide all the input code cells.

Example:

rsconnect deploy notebook \
   --server https://connect.example.org:3939 \
   --api-key my-api-key \
   --hide-all-input \
   --new \
   --title="My Notebook" \
   mynotebook.ipynb

This example will deploy a new notebook document with source code to an RStudio Connect server. To update (republish) an existing content item, remove the --new flag. To publish the content as a static document (non-executable content) on RStudio Connect, include the --static flag. Run rsconnect deploy notebook --help to see the full set of supported options.

To generate a manifest file with all input code cells hidden, use the --hide-all-input flag with the write-manifest option:

rsconnect write-manifest notebook \
   --hide-all-input \
   mynotebook.ipynb

To overwrite an existing manifest in the content directory, include the --overwrite flag. Run rsconnect write-manifest notebook --help to see the full set of supported options.

Hide Only Tagged Input Code Cells#

If you want the flexibility to hide some input code cells while keeping others, this can be accomplished with cell tags. Cell tags were added to the Jupyter Notebook ecosystem as a lightweight way to create more granual levels of customization and control in combination with tools like nbconvert. The publishing mechanisms built for RStudio Connect can leverage nbconvert to hide tagged cells, but the tag must be named hide_input.

To hide only the tagged cells, first enable Tags in the View > Cell Toolbar menu:

Enable Tags in the Cell Toolbar menu

Once enabled, tag each cell where you would like to hide the input code:

  • Enter hide_input into the text field.
  • Click Add tag to apply the tag to a code cell.

Publishing Plugin Method#

After tagging all the desired cells, select Hide input code cells with the "hide_input" tag in the publishing plugin dialog.

Add the hide_input tag to individual cells before publishing

Note

The publishing plugin can also be used to generate a manifest for git-backed publishing. Learn more here.

CLI Method: rsconnect-python#

When publishing a Jupyter notebook with the rsconnect-python CLI, include the --hide-tagged-input flag to hide only the tagged input code cells.

Example:

rsconnect deploy notebook \
   --server https://connect.example.org:3939 \
   --api-key my-api-key \
   --hide-tagged-input \
   --new \
   --title="My Notebook" \
   mynotebook.ipynb

This example will deploy a new notebook document with source code to an RStudio Connect server. To update (republish) an existing content item, remove the --new flag. To publish the content as a static document (non-executable content) on RStudio Connect, include the --static flag. Run rsconnect deploy notebook --help to see the full set of supported options.

To generate a manifest file with all input code cells hidden, use the --hide-tagged-input flag with the write-manifest option:

rsconnect write-manifest notebook \
   --hide-tagged-input \
   mynotebook.ipynb

To overwrite an existing manifest in the content directory, include the --overwrite flag. Run rsconnect write-manifest notebook --help to see the full set of supported options.

Tracking Visits#

Connect records visits to Jupyter notebooks and lets you see:

  • Which documents were viewed
  • When the documents were viewed
  • Who viewed the documents

Details about visits are also recorded for parameterized R Markdown documents and other types of rendered and static content.

An overview of recent activity is available in the RStudio Connect dashboard. See the Content Settings Panel section to learn more.

Details about each visit are available through the Instrumentation APIs. Use these records to perform your own analysis. Code examples showing how to obtain this data can be found in the User Activity section of the RStudio Connect: Server API Cookbook.