Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using nbconvert to hide all input cells?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading