【问题标题】:How can I load external static Javascript files in ipython or jupyter notebook如何在 ipython 或 jupyter notebook 中加载外部静态 Javascript 文件
【发布时间】:2017-04-05 14:40:18
【问题描述】:

我正在尝试在 ipython 笔记本中加载 d3 和 dimple.js,但它抛出错误。我也尝试过 require 但无法加载请给我一些解决方法

【问题讨论】:

  • 你需要 node.js 内核来运行你的notenook。

标签: javascript python requirejs ipython jupyter-notebook


【解决方案1】:
  1. 在笔记本中运行此命令以找出您的 jupyter 目录:

    from jupyter_core.paths import jupyter_config_dir
    jupyter_dir = jupyter_config_dir()
    jupyter_dir
    
  2. 在上面找到的 jupyter 目录下创建名为“custom”的文件夹 /自定义

  3. 在 /custom/custom.js 下创建 custom.js 文件并添加以下内容

    requirejs.config({
    paths: {
        d3: 'd3.min',
    }
    });
    
  4. 打开为您的个人资料创建的 jupyter_notebook_config.py。如果未创建,请使用以下命令从命令行/终端创建一个

    jupyter notebook --generate-config
    
  5. 修改 jupyter_notebook_config.py 中 js 文件夹的静态路径(从 generate-config 命令创建),如下所示

    c.NotebookApp.extra_static_paths = ["C:\your-js-folder"]
    
  6. 将外部 js 文件拖放到 C:\your-js-folder 下,然后停止并启动 jupyter notebook

【讨论】:

    猜你喜欢
    • 2018-04-23
    • 2020-03-06
    • 2013-07-22
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 2015-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多