Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JupyterLab : The widget returned by plotter.show(return_viewer=True) isn't updated when the plotter is #2940

Closed
1 task done
leilakany opened this issue Jul 4, 2022 · 2 comments · Fixed by #3385
Closed
1 task done
Labels
bug Uh-oh! Something isn't working as expected.

Comments

@leilakany
Copy link

Describe the bug, what's wrong, and what you expected.

I am trying to have a widget returned by the method plotter.show(return_viewer=True) interact with an ipywidget slider in JupyterLab and pythreejs backend, but the widget scene doesn't get updated when the plotter actors change.

However, I works as expected with the @interact decorator.

Steps to reproduce the bug.

Doesn't work as expect

import pyvista as pv
from ipywidgets import widgets
pv.start_xvfb()
pv.set_jupyter_backend('pythreejs')
from pyvista import examples
from ipywidgets import interact

new_plotter = pv.Plotter()
vol = examples.download_brain()
slice = vol.slice()
new_act = [None]
new_act[0] = new_plotter.add_mesh(slice)

int_range =  widgets.IntSlider(min=0, max=180, step=1, )

widget = new_plotter.show(interactive_update=True, return_viewer=True, auto_close=False)

def update_slice(change):
    x = change["new"]
    new_slice = vol.slice(origin=(x, 0, 0))
    new_plotter.remove_actor(new_act[0], render=False, reset_camera=False)
    new_act[0] = new_plotter.add_mesh(new_slice, render=False, reset_camera=False)
    new_plotter.update()
    new_plotter.show()

int_range.observe(update_slice, names=['value'])

display(int_range, widget)
 

Works as expected

import pyvista as pv
from ipywidgets import widgets
pv.start_xvfb()
pv.set_jupyter_backend('pythreejs')
from pyvista import examples
from ipywidgets import interact

vol = examples.download_brain()
p = pv.Plotter()
slice = vol.slice()
actors = [None]
actors[0] = p.add_mesh(slice)
p.show(interactive_update=True, return_viewer=True, auto_close=False)

@interact(x=(0.0,180.0,1.0), continuous_update=False)
def update_slice(x):
    slice = vol.slice(origin=(x, 0, 0))
    p.remove_actor(actors[0], render=False, reset_camera=False)
    actors[0] = p.add_mesh(slice, render=False, reset_camera=False)
    p.show(interactive_update=True, auto_close=False)

System Information

--------------------------------------------------------------------------------
  Date: Mon Jul 04 16:53:41 2022 UTC

                OS : Linux
            CPU(s) : 8
           Machine : x86_64
      Architecture : 64bit
               RAM : 54.9 GiB
       Environment : Jupyter
        GPU Vendor : VMware, Inc.
      GPU Renderer : llvmpipe (LLVM 10.0.0, 256 bits)
       GPU Version : 3.3 (Core Profile) Mesa 20.0.8

  Python 3.8.0 (default, Dec  9 2021, 17:53:27)  [GCC 8.4.0]

           pyvista : 0.33.2
               vtk : 9.0.1
             numpy : 1.19.5
           imageio : 2.9.0
           appdirs : 1.4.4
            scooby : 0.5.7
        matplotlib : 3.3.4
           IPython : 7.16.1
        ipyvtklink : 0.2.2
             scipy : 1.8.1
              tqdm : 4.60.0
            meshio : 4.4.1
--------------------------------------------------------------------------------

Screenshots

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@leilakany leilakany added the bug Uh-oh! Something isn't working as expected. label Jul 4, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2022

Hi and welcome! Thanks for posting your first issue in the PyVista project! Someone from @pyvista/developers will chime in before too long. If your question is support related, we may transfer it to the Discussions.

@banesullivan
Copy link
Member

Hi @leilakany, this is a great feature request!

At this time, the pythreejs notebook viewer for the Plotter is statically serializing/exporting the scene which is why you aren't seeing the threejs scene in the notebook update after modifying the original Plotter.

Your @interact decorated function is actually re-serializing the scene with the additional p.show() call - this is why it seemingly updates, but this could have very poor performance for many use cases.

At this time, I think the best way to have a reactive and interactive plotter in a notebook is with the ipyvtklink backend though more options and features are definitely on our roadmap, so stay tuned!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Uh-oh! Something isn't working as expected.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants