ResidentMario / py_d3

D3 block magic for Jupyter notebook.
MIT License
450 stars 40 forks source link

Use requirejs to load d3 #2

Closed akre54 closed 8 years ago

akre54 commented 8 years ago

d3 version 4.0 no longer exposes the d3 global (https://github.com/d3/d3/issues/2615) when in a requirejs environment (like Jupyter).

Instead of a <script> tag, you'll need to set up the path first:

requirejs.config({
    paths: {
        d3: 'https://d3js.org/d3.v4.js' // Or whatever
    }
})

And then later:

require(['d3'], function(d3) {
 // run d3 logic here. maybe set window.d3 = d3
})
ResidentMario commented 8 years ago

Yes, this is exactly right. I've patched it, should now work in 4.x. Let me know if there are any issues.

Some more references: here, here, here, here.

jugi92 commented 7 years ago

actually I had to leave out the .js at the end of the d3 path because requirejs added it automatically and it was thus trying to call https://d3js.org/d3.v4.js.js which returns 404.

Code that worked for me in jupyter:

requirejs.config({
    paths: {
        d3: 'https://d3js.org/d3.v4'
    }
});

require(['d3'], function(d3) {
 window.d3 = d3;
});
bendavidwhite commented 6 years ago

Hi there,

I'm hoping someone can save me from a newbie error! I've tried the approach above but i still can't seem to load d3 v4. Only v3 :-(

I'm using Jupyter notebook v5.0.0 and py-d3-0.2.7.

Here's a screen shot - please let me know if you can spot anything wrong.

Many thanks in advance Ben

image

mondeja commented 6 years ago

Run in your notebook:

In [1]: %d3 version

If you obtain an error then reinstall py_d3 with pip install py_d3 --update.

bendavidwhite commented 6 years ago

Hi, thank you for the quick response! :+1:

I tried the %d3 version command but got an error even after updating with pip (version is 0.2.7)

image

ResidentMario commented 6 years ago

I believe that mondeja added the version functionality in his recent PR, and I haven’t pushed that to PyPi yet! Whoops.

You can either install from master (pip install https://github.com/ResidentMario/py_d3.git) or you can wait a couple of days until I get the new py_d3 version out on PyPi. ​

On Wed, Mar 28, 2018 at 4:53 AM, bendavidwhite notifications@github.com wrote:

Hi, thank you for the quick response! πŸ‘

I tried the %d3 version command but got an error even after updating with pip (version is 0.2.7)

[image: image] https://user-images.githubusercontent.com/32987465/38018714-9985bd3a-326d-11e8-97a0-6f357fb940c6.png

β€” You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ResidentMario/py_d3/issues/2#issuecomment-376811736, or mute the thread https://github.com/notifications/unsubscribe-auth/ADTkZUSq0yQxC-dFKdIVivqydss_OmfZks5ti09-gaJpZM4KB_Pz .

--

Aleksey Bilogurhttp://residentmar.io https://github.com/ResidentMario/

ResidentMario commented 6 years ago

Fixes are now live in the newly-released 0.3.0! πŸŽ‰

@mondeja if you want to submit a PR with the additional blog builder API surface, now is the time. πŸ˜ƒ

@bendavidwhite let me know if you have any issues after doing a pip install -u py_d3 to get the latest version.

bendavidwhite commented 6 years ago

Thanks @ResidentMario, I ended up downloading and installing the repo directly. It worked. Thank u!