Home > Software engineering >  Using nbconvert to hide all input cells?
Using nbconvert to hide all input cells?

Time:04-26

I have a two cells in a Jupyter notebook, one which defines a function, and one which executes said function (I've provided a simplified function as of now). Currently, I include a bash command within the function to convert this notebook to a html file using nbconvert:

Current output/notebook.ipynb


Cell 1

summary_gen(filepath):

    for summary in Path(filepath).rglob('*.txt'):
        txt= str(txt)

    print(bam)
    !jupyter nbconvert "/path/to/this/notebook.ipynb"



Cell 2

Summary_gen("/path/to/file") 
  • Secondary: 1374881 0
  • Supplementary: 0 0
  • Duplicates: 0 0

However, although I can output my entire notebook, my goal is to use nbconvert to output a html which only contains the output of the function, meaning when I run the function, I get a html like so:

Desired output


  • Secondary: 1374881 0
  • Supplementary: 0 0
  • Duplicates: 0 0

I think this is possible using some form of:

  • jupyter nbconvert mynotebook.ipynb -TagRemovePreprocessor.enabled=True --TagRemovePreprocessor.remove_cell_tags remove_cell

or even the regex version:

  • jupyter nbconvert --RegexRemovePreprocessor.patterns="['some_pattern']" mynotebook.ipynb

However, I admit I'm not entirely sure how to tag cells, or if there might be a better solution.

As always any help is appreciated!

CodePudding user response:

You can pass the argument --no-input to hide all the input cells in the output document.
You can just use it as:

jupyter nbconvert --no-input notebook.ipynb

You can also add --no-prompt to hide the prompts and have all the cells vertically aligned.

More information of the configurations options in the docs

  • Related