Panel meets K3D-jupyter

I had almost decided to hack the Function grapher at https://github.com/stemkoski/stemkoski.github.com
when I came across https://github.com/K3D-tools/K3D-jupyter/

One puzzle remains: The graph is added to a pn.pane.Pane.
Setting a size for the pane displays the plot, but the actual plot size
is slightly larger than the pn pane for some reason.
Any clue how to fix this would be appreciated!!

The notebook with the code is on gitlab:
https://gitlab.com/ea42gh/elementary-linear-algebra/-/blob/master/QuadricSurfaceDisplay.ipynb

4 Likes

Really Nice. Thanks for sharing. :+1:

have you tried setting the margin of the Pane to 0? Does it work?

1 Like

yes! margin=15 did the trick! Thank you @Marc

1 Like

Great you got it working @ea42gh.

How does the K3D-jupyter control compare to VTK? Could you do the same with VTK?

I have not used VTK in a very long time…
K3D-jupyter proved very simple.
From its documentation, it is supposed to play nicely with VTK.

1 Like

Hi @ea42gh.

When I add .servable() to the notebook and run it via `panel serve QuadricSurfaceDisplay.ipynb’ it looks like

and there are errors in the console.

Do you know why that is?. And how to solve it?

@Marc,
no, I have not seen that yet.
What I do see:

  • the repository code works in Chromium
  • the repository code does not work in firefox:
    it fails to load with an error
    failed to load https://unpkg.com/@holoviz/panel@^0.10.2/dist/panel.min.js
    in the console…
  • what change did you make to the notebook before serving it?
    I’d like to see if I can duplicate what you are seeing

Hi @ea42gh

The only thing I’ve done is to add .servable() like below

Then I run it with panel serve QuadricSurfaceDisplay.ipynb and get the errors.

For reference I’ve attached the modified notebook.

QuadricSurfaceDisplay.ipynb (48.2 KB)

I don’t need it working for work. But it would be nice to show case that it’s possible to serve apps using k3d. There are a lot of cool examples in their docs.

Any help is appreciated. Even just a bug report on Github :slight_smile:

Weird:
when I try to serve the notebook and open it in either Firefox or Chromium, I get

b1f0>: No module named 'ipywidgets_bokeh'
File "ipywidget.py", line 23, in _get_ipywidget:
from ipywidgets_bokeh.widget import IPyWidget Traceback (most recent call last):
  File "/home/user/.local/lib/python3.8/site-packages/bokeh/application/handlers/code_runner.py", line 197, in run
    exec(self._code, module.__dict__)
  File "/home/user/CODE/Langs/Julia/elementary-linear-algebra/QuadricSurfaceDisplay.ipynb", line 153, in <module>
    "  }\n",
  File "/home/user/.local/lib/python3.8/site-packages/panel/viewable.py", line 313, in servable
    self.server_doc(title=title, location=True)
  File "/home/user/.local/lib/python3.8/site-packages/panel/viewable.py", line 749, in server_doc
    model = self.get_root(doc)
  File "/home/user/.local/lib/python3.8/site-packages/panel/viewable.py", line 482, in get_root
    root = self._get_model(doc, comm=comm)
  File "/home/user/.local/lib/python3.8/site-packages/panel/layout/base.py", line 112, in _get_model
    objects = self._get_objects(model, [], doc, root, comm)
  File "/home/user/.local/lib/python3.8/site-packages/panel/layout/base.py", line 102, in _get_objects
    child = pane._get_model(doc, root, model, comm)
  File "/home/user/.local/lib/python3.8/site-packages/panel/pane/ipywidget.py", line 38, in _get_model
    model = self._get_ipywidget(self.object, doc, root, comm, **kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/panel/pane/ipywidget.py", line 23, in _get_ipywidget
    from ipywidgets_bokeh.widget import IPyWidget
ModuleNotFoundError: No module named 'ipywidgets_bokeh'

So I installed ipywidgets_bokeh.

Now I get:

Model 'ipywidgets_bokeh.widget.IPyWidget' does not exist. This could be due to a widget or a custom model not being registered before first usage.
1 Like

Really weird: upgraded some libraries. Current status:

  • chromium partially displays the GUI. The plot appears to be a tiny little area at the top left.
    Console shows:
ipywidgets_bokeh.js:1 TypeError: Cannot read property resizeHelper of undefined
    at r.handleResize (k3d.js:563)
  • Firefox yields an empty display with
    Uncaught ReferenceError: requirejs is not defined
1 Like

This used to work. Since pn.pane.Pane no longer exists,
I tried to use pn.panel instead.
I no longer can get the surface displayed.

Does anybody have any suggestions?
I really would like to use this in a class :frowning:
The code is in

displaying the surface directly with quadric.plot does work however

1 Like

Could you provide a minimum, reproducible example with screenshot? That would help the next user Thanks.

import numpy as np
import k3d
import panel as pn
pn.extension()

plot=k3d.plot()
plot += k3d.points( np.random.randn(100), point_size=0.1)
print(type(plot))

<class ‘k3d.plot.Plot’>

plot will display the plot.
Trying to use pn.panel(plot) will yield an empty output cell of the correct size.

This used to work with pn.pane.Pane(plot)

Some progress: pn.panel(plot.display())
will show the plot.
The problem now is that I cannot control the width of the plot!?

Any ideas, anyone?

I can get you simple example to work. But try to check the type of pn.panel(plot.display()). I would suspect it is a pn.pane.XXX, you should be able to use that as you did with pn.Pane before.

turns out to be panel.pane.markup.Str which leaves me totally puzzled!
Are you saying you can control both height and width of the plot? I can only get to get the height to work, e.g., by setting plot.height=500

actually it’s worse: plot.display() does show the plot, but outside of panel :frowning:

Is the functionality of pn.pane.Pane subsumed in any other panel?
This used to work!