【问题标题】:How export a Jupyter notebook to HTML from the command line?如何从命令行将 Jupyter 笔记本导出为 HTML?
【发布时间】:2016-08-22 10:04:53
【问题描述】:

我正在根据测试结果编写测试可视化程序。 我想通过终端运行 jupyter notebook 并生成 html 页面以将其显示给用户,而不向用户显示可编辑的脚本。 我可以这样做吗?或者建议更好的方式来显示可视化的测试结果。

【问题讨论】:

  • nbconvert 可以执行笔记本并将其转换为 HTML(或其他格式)。要隐藏代码,您需要custom template。

标签: python jupyter-notebook visualization jupyter


【解决方案1】:

我开发了 jupyter-runner (https://github.com/omar-masmoudi/jupyter-runner),它是一个简单的“jupyter nbconvert”包装器。

可以使用参数、并行工作程序、位于 S3 中的输入/输出和邮件发送功能来执行多个笔记本。

【讨论】:

    【解决方案2】:

    同样使用--execute获取输出

    jupyter nbconvert --execute --to html notebook.ipynb
    

    这会产生一个notebook.html 文件。

    最佳做法是将输出保留在笔记本之外以进行版本控制,请参阅:Using IPython notebooks under version control

    但是,如果您不传递 --execute,则输出将不会出现在 HTML 中,另请参阅:How to run an .ipynb Jupyter Notebook from terminal?

    对于没有标题的 HTML 片段:How to export an IPython notebook to HTML for a blog post?

    在 Jupyter 4.4.0 中测试。

    【讨论】:

      【解决方案3】:

      是的,你可以,而且它非常简单,并且是一个内置功能

      jupyter nbconvert --to html notebook.ipynb
      

      这将生成一个 notebook.html 文件。输出can be customized。还可以查看幻灯片功能(查看>单元格工具栏>幻灯片),它也可以与 nbconvert 一起使用。

      还可以将 notebook.ipynb Jupyter 文件上传到呈现当前版本的 Github。根据您想要的信息,这些信息也可能有用

      还可以查看线/单元魔术。您可以像这样直接在 jupyter 单元中运行 bash 命令:

      %%bash
      convert graphviz/MyPic.jpg -resize 70% graphviz/MyPic_sm.jpg
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多