danielfrg / pelican-jupyter

Pelican plugin for blogging with Jupyter/IPython Notebooks
Apache License 2.0
422 stars 105 forks source link

Hiding a notebook cell #118

Open charlet-antoine opened 4 years ago

charlet-antoine commented 4 years ago

Hi everyone,

I'm a new user of pelican and this plugin and I was wondering if it was possible to hide a specific notebook cell to make it non visible once my notebook is published with pelican. One of my use cases is that usually my notebook start by the classic: import pandas as pd import numpy as np import matplotlib.pyplot as plt

etc... but I see really few value making this cell visible in my blog posts. Is this feature already implemented in the plugin? Otherwise do you have any ideas how I could do that easily ?

Thank you by advance for your help.

Antoine,

dclong commented 4 years ago

Both jupyter-book and fastpages support this feature.

Zottel commented 3 years ago

The only way that worked for me was this:

IPYNB_PREPROCESSORS=[
        nbconvert.preprocessors.ExecutePreprocessor(timeout=300),
        nbconvert.preprocessors.RegexRemovePreprocessor(patterns=['.*PREAMBLE.*'])]

Then every cell that contains PREAMBLE is executed but removed from the pelican output. Example:

# PREAMBLE
import numpy, pandas, seaborn
...
Zottel commented 3 years ago

Although it would be nice to have all (previous) cells execute when giving Subcells: [2, None] in the metadata.

izikeros commented 3 years ago

I have achieved removing cell from the pelican output with removing cell by assigning given tag and configuring preprocessor.

Steps:

  1. Add tag remove_cell to the cell that has to be removed (in Jupyter notebook use: View -> Cell Toolbar -> Tags)
  2. Add notebook preprocessing configuration to pelicanconf.py:
    from nbconvert.preprocessors import TagRemovePreprocessor
    from traitlets.config import Config
    c = Config()
    c.TagRemovePreprocessor.remove_cell_tags = ("remove_cell",)
    c.TagRemovePreprocessor.enabled = True
    IPYNB_PREPROCESSORS=[TagRemovePreprocessor(config=c)]

    Reference: Removing cells, inputs, or outputs - nbconvert documentation