Closed hyanwong closed 4 months ago
I also tried downloading and using a local copy of d3js (see below), but then I get Source Map Loading Errors
Ah yes, thanks for catching that. I haven't used Colab before, but it looks like this requires a different method for loading D3 into that environment. This notebook with the d3blocks
package has figured it out so I'll look into what they are doing to get it to work. Interestingly, there isn't any obvious loading statement in the notebook itself, so I wonder if there is a cleaner way to load D3 across all of the different environments.
Thanks. It would be great if there is a clean way without the user having to type/figure out the JS.
Alright, this turned out to be a naming issue for the Notebook environment. running_in_notebook()
determines whether the package is being executed in a notebook or regular Python (command line, etc). It either displays the ARG within the notebook or, in the latter case, launches the web browser to show the ARG. Google Colab has get_ipython().__class__.__name__ == "Shell"
rather than the standard get_ipython().__class__.__name__ == "ZMQInteractiveShell"
used by Jupyter Notebook and Lab, so it wasn't catching that it should be displayed in the notebook. At the same time, the notebook was preventing a browser from being launched, so the HTML was just getting discarded. Adding an extra check for "Shell" solves this.
Additionally, it appears that you do not need the header to load D3.js in Google Colabs. I've also found that the header may not be important for Jupyter Lab but is still needed for Jupyter Notebook. Still confirming this last bit, but please let me know if you have issues with the changes thus far.
Yep, that works. Thanks for the quick reply and fix!
I'm trying to get
tskit_arg_visualizer
to work in colab (see screenshot). At the moment, nothing appears when executing the visualiser code. I suspect the issue is that each cell is sandboxed. Additionally I getCan't find variable: require
when using the Jupyter notebook incantation in a separate colab cell (when I try the JupyterLab version it doesn't complain, however).I tried a workaround loading the javascript directly in the same cell using
But then I get
HTTPError: HTTP Error 403: Forbidden