1

I want to run a python program (not command line) using papermill to execute a jupyter notebook and then transform it into a PDF. The idea is working, but I'm unable to hide the input cells.

For papermill report_mode = True is supposed to hide input cells, but there seems to be a problem with jupyter Classic (https://github.com/nteract/papermill/issues/130)

Other extension like hide_input or html scripts are also not sufficient. Maybe a nbconvert template for hide cells is a solution, but I didn't get that running.

My minimal Code:

pm.execute_notebook(
        "Input.ipynb",
        "Output.ipynb",
        parameters=dict(id=id),
        report_mode=True,
    )
notebook_filename = "Output.ipynb"

with open(notebook_filename) as f:
    nb = nbformat.read(f, as_version=4)
pdf_exporter = PDFExporter()
pdf_data, resources = pdf_exporter.from_notebook_node(nb)

So I'm looking for a way to execute the Notebook, hide the input cells and transform the Notebook to a PDF. I want to use nbconvert in Python and not as a command line tool, since the Script shall run daily.

TheTiger
  • 13,035
  • 3
  • 55
  • 79
PKL
  • 63
  • 7

1 Answers1

2

I know you said you "don't want to use command line", but how about having your python script execute a subprocess command after running papermill? Mixing with this answer:

import subprocess

subprocess.call('jupyter nbconvert --to pdf --TemplateExporter.exclude_input=True Output.ipynb')
cwalvoort
  • 1,675
  • 1
  • 13
  • 17
  • 1
    Thanks for the idea, could work with some twerking. I had issues with the Shell / Interpreter trying the approach. The solution I found is, to just add the line: `pdf_exporter.exclude_input = True` – PKL Aug 09 '19 at 09:30