对于用Jupyter Notebook编写的python脚本,如果可以将较长的代码部分隐藏,只显示Markdown说明文本、和代码块的运行结果,便可将脚本直接用作动态分析报告。即在保持可读性的同时,可通过刷新原数据/调整代码即时生成新的报告内容。
实现显示/隐藏代码块的步骤:
安装jupyter_contrib_nbextentions
(Ref: https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/install.html#install-the-python-package)
conda安装命令:conda install -c conda-forge jupyter_contrib_nbextensions
python安装命令:pip install jupyter_contrib_nbextensions安装jupyter_nbextentions_contributor,以便在Jupyter Notebook页面设置nbextentions
(Ref: https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator)
conda安装命令:conda install -c conda-forge jupyter_nbextensions_configurator
python安装命令:pip install jupyter_nbextensions_configurator-
安装完成后,点击Jupyter Notebook首页的Nbextensions标签,打开在Nbextensions configuration设置页面。
1)勾选Hide input(显示/隐藏选定代码块)
2)勾选Hide input all(显示/隐藏所有代码块)
-
打开任意python脚本文件,可看到工具栏中已添加相应的按钮。