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
916 stars 123 forks source link

How could one integrate k3d with pyviz panels? #447

Open ea42gh opened 5 months ago

ea42gh commented 5 months ago

Description

panel used to have a pane that would display k3d plots. That pane is no longer available due to code refactoring.

I suspect using one of the current panes might work easily, but do not know how to integrate the two?

ichko commented 3 months ago

Hey, I also stumbled upon this issue.

Minimal code example to reproduce in a notebook environment:

import k3d
plot = k3d.Plot()
plot += k3d.points([0, 0, 0])

pn.Column("a", pn.panel(plot), "b")

and the generated plot is empty.

Going to the console you get this error message:

TypeError: world.cleanup is not a function
    at K3D.disable (Core.js:1217:1)
    at refresh (Canvas.js:211:1)
    at module.exports (Canvas.js:281:1)
    at new K3D (Core.js:1234:1)
    at PlotView._init (k3d.js:323:1)
    at f (backbone.js:335:57)
    at g (backbone.js:322:19)
    at d (backbone.js:110:16)
    at a.trigger (backbone.js:312:5)
    at r.render (panel.min.js:120:1118)

and this comes from a part of the code responsible for k3d teardown... maybe..

image

going up a stack frame:

image

It is interesting that the error occurs whilst teardown, which I suppose is not what we want while trying to show a plot.

There is also an unresolved discussion about this in the holoviz forum - https://discourse.holoviz.org/t/panel-meets-k3d-jupyter/1604/17

I would love to be able to show a k3d plot in a panel application.