使用NBConvert隐藏所有输入单元格?
我在jupyter笔记本中有一个两个单元格,一个定义了一个函数,一个执行该功能的函数(截至目前,我提供了一个简化的函数)。当前,我在该函数中包含一个bash命令,以使用nbconvert:
当前输出/笔记book.ipynb
单元格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
- 补充:0 + 0
- 重复:0 + 0 ,
但是,尽管我可以输出整个笔记本,我的目标是使用nbconvert要输出仅包含函数输出的HTML ,这意味着当我运行该函数时,我会得到一个像So:
所需的输出
- sependary:1374881 + 0
- readmentary: 0 + 0
- 重复:0 + 0
我认为这是可以使用某种形式的:
jupyter nbconvert mynotebook.ipynb -tagremovepreprocessor.enabled = true = true -true-tagremovepreemovepreprocessor.remove_cell_cell_cell_cell_cell_cell_cell_cell_cell emove_cell emove_cell emove_cell emove_cell < /code>
,甚至是正则版本:
jupyter nbconvert -regexremovepreprocessor.patterns =“ ['some_pattern']” mynotebook.ipynb
但是,我承认我不完全确定如何标记单元,或者如果有更好的解决方案。
与往常一样,任何帮助都将受到赞赏!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以传递参数
- no Input
以隐藏输出文档中的所有输入单元格。您可以将其使用为:
jupyter nbconvert -no-Input Notebook.ipynb
您还可以添加
- 无启示>
隐藏提示对齐。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