如何在ipython或jupyter笔记本中加载外部静态Javascript文件 [英] How can I load external static Javascript files in ipython or jupyter notebook

查看:322
本文介绍了如何在ipython或jupyter笔记本中加载外部静态Javascript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在ipython笔记本中加载d3和dimple.js,但是它会抛出错误.我也尝试过需求,但无法加载,请提供一些解决方法

I am trying to load d3 and dimple.js in ipython notebook but its throwing error. I have tried require as well but not able to load please provide me some way out of it

推荐答案

  1. 在笔记本中运行此命令以找到您的jupyter目录:

  1. Run this in the notebook to find out your jupyter directory:

from jupyter_core.paths import jupyter_config_dir
jupyter_dir = jupyter_config_dir()
jupyter_dir

  • 在从上方找到的jupyter目录下创建名为"custom"的文件夹 /custom

  • Create folder named 'custom' under jupyter directory found from above /custom

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

    Create custom.js file under /custom/custom.js and add following

    requirejs.config({
    paths: {
        d3: 'd3.min',
    }
    });
    

  • 打开为您的个人资料创建的jupyter_notebook_config.py.如果未创建,请使用以下命令从命令行/终端创建一个

  • Open jupyter_notebook_config.py created for your profile. if it is not created ,use the following to create one from the command line/terminal

    jupyter notebook --generate-config
    

  • 在jupyter_notebook_config.py(通过generate-config命令创建)中修改js文件夹的静态路径,如下所示

  • Modify static path for your js folder in jupyter_notebook_config.py(created from generate-config command) like below

    c.NotebookApp.extra_static_paths = ["C:\your-js-folder"]
    

  • 将外部js文件拖放到C:\ your-js-folder下,然后停止并启动jupyter notebook

  • Drop your external js file under C:\your-js-folder and stop and start jupyter notebook

    这篇关于如何在ipython或jupyter笔记本中加载外部静态Javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆