Notebooks executed through jobs don't show rich output

Posting here as I realized this might be a more general issue since this is not working with multiple tools.

What I am trying to do:
Run notebooks in an automated way to generate notebooks as reports which have graphical output, using the three tools to parameterize them.

The issue:
plots don’t show up, rich pandas tables (style method applied and shown as html) also don’t show.

What I have tried:
The simplest example, take a notebook and run:

import altair as alt
import pandas as pd

source = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})

alt.Chart(source).mark_bar().encode(
    x='a',
    y='b'
)

The plot will show up fine.

But when the notebook is ran through (in my testing the below three):

  • Jupyter Scheduler
  • papermill
  • ploomber

None of them have the outputted notebook retaining the plots.

Does anyone know why this might be or if I am overlooking something or some configuration option in jupyterlab?

Note, I did originally post here: Ability to store charts and rich tables · Issue #570 · jupyter-server/jupyter-scheduler · GitHub
but then tried the other tools and realized this seems to be a more general issue.

Additional detail which is probably not necessary since this seems to be the a case with jupyterlab,
The Jupyter Scheduler is just a standard job:

For ploomber it is ran with code like this:

from ploomber_engine import execute_notebook
nb = execute_notebook('basic.ipynb', output_path='basic_candy.ipynb')

What are you seeing is covered in this reply to an issue ’ plot not rendering’ about papermill:

“So the issue is that the notebook is outputting javascript in the plot and for security reasons the classic notebook does not render javascript imported from external sources. To get around this go to File → Trust Notebook and then the plot will appear.”

In your case, it is because when the notebook gets opened after you made it on the command line, it will not open as trusted. (When you are running code in it Jupyter actively, it is trusted. This was the situation you had when you said, “The plot will show up fine.”)
So just trust it and it will render those parts of the output fully.

You can also set trust on the command line as this will be easier for you since you are using command line already, plus the trust setting isn’t as easy to find in JupyterLab (it is there under the Command Palette though):

jupyter trust *.ipynb

I know I linked to a post about plots; however, the same holds for the ‘extras’ that a styled dataframe has. Without adjusting the trust level of the command-line run Jupyter .ipynb file, the syled dataframe will render some but without the colors and things that you may want to show with styling. Trusting will restore it fully as the code is all in the Jupyter .ipynb file as you can see by opening it in your favorite text editor.

2 Likes