K3D-tools / K3D-jupyter

K3D lets you create 3D plots backed by WebGL with high-level API (surfaces, isosurfaces, voxels, mesh, cloud points, vtk objects, volume renderer, colormaps, etc). The primary aim of K3D-jupyter is to be easy for use as stand alone package like matplotlib, but also to allow interoperation with existing libraries as VTK.
MIT License
921 stars 123 forks source link

404 GET /static/k3d.js #324

Closed nlgranger closed 2 years ago

nlgranger commented 2 years ago

When installing k3d via pip in a clean conda environment and using jupyter notebook, the plot won't show up and the console reports:

[W 12:30:01.933 NotebookApp] 404 GET /static/k3d.js?v=20220104122942 (127.0.0.1) 9.910000ms referer=http://localhost:8888/notebooks/scripts/preview.ipynb

k3d works when installed via conda using conda-forge channel.

nlgranger commented 2 years ago

Apparently one simply needs to manually enable the jupyter extension:

jupyter nbextension install --py --user k3d
jupyter nbextension enable --py --user k3d

I'm gonna leave this issue open till the documentation mentions it if you don't mind.

tgandor commented 2 years ago

Hi Nicolas, while the commands you mentioned are not necessary in all circumstances (since Notebook 7.x there is a mechanism for auto-installation; I think the conda-forge version also doesn't need it). However, these commands shouldn't hurt in any case, so I added them to the README. This will be merged to main in the next release, so stay tuned.

Also, we were getting questions about this earlier, especially after users upgraded their K3D and got a Python/JS version mismatch. So I also put there a note about upgrade.

nlgranger commented 2 years ago

Great, thank you (and thanks for this project too, it works really well and is simple to use).

ChHarding commented 5 months ago

Based on 86cucv's comment about running k3d within a docker notebook, I've tried the same but within a colab notebook.

I run!jupyter nbextension install --py --user k3d and !jupyter nbextension enable --py --user k3d and the validations both show OK.

I then run this code:

from k3d.helpers import download
import k3d
plot = k3d.plot()
filename = download('https://upload.wikimedia.org/wikipedia/commons/a/af/Asad_Al-Lat.stl')
plot += k3d.stl(open(filename, 'rb').read())
plot.display()

which should give me this: image

however, I only see this: image

Any idea why the stl doen't get "attached" to the viewer within colab?

artur-trzesiok commented 5 months ago

Hi @ChHarding

As We explain here: https://github.com/K3D-tools/K3D-jupyter?tab=readme-ov-file#google-colab

For Google Colab you need to activate custom widgets and switch k3d to text protocol:

import k3d
from google.colab import output

output.enable_custom_widget_manager()

k3d.switch_to_text_protocol()

The reason for that is that colab has no support to binary websockets

ChHarding commented 5 months ago

Thank you but that still doesn't work. I read up on how to activate custom widgets but this might be wrong(?) Here's what I'm doing:

image

Any idea what I'm doing wrong?

Thanks!