Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Hiding a notebook cell #118

Open
charlet-antoine opened this issue Apr 23, 2020 · 4 comments
Open

Hiding a notebook cell #118

charlet-antoine opened this issue Apr 23, 2020 · 4 comments

Comments

@charlet-antoine
Copy link

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
Copy link

dclong commented Sep 11, 2020

Both jupyter-book and fastpages support this feature.

@Zottel
Copy link

Zottel commented Dec 24, 2020

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
Copy link

Zottel commented Dec 24, 2020

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

@izikeros
Copy link

izikeros commented Oct 7, 2021

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants