GithubHelp home page GithubHelp logo

Comments (8)

GuillaumeFavelier avatar GuillaumeFavelier commented on June 19, 2024 1

I thought I had the panel code to only run if the code is being executed from a Jupyter notebook.

And yes, it works as expected. My bad, it was not clear. What I mean is, I had to use a workaround in my specific use case because I expect that any call to .show() will show the renderer (c.f. plot_sphere_1() scenario) even if it's not the cell's output.

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024 1

Do you think there would be a way to integrate such a feature in PyVista

Probably - we should add something like this in pyvista/pyvista#300. My only hesitation is that the url and port have to be known, and they might not always be notebook_url="localhost:8888", port=0 so maybe we should ping the panel dev team.

Frankly, I think all notebook related dev should be paused until a few things move forward with itk-jupyter-widgets. Reference InsightSoftwareConsortium/itkwidgets#154 and waiting on:

Once those two issues are addressed, we will favor using itk-jupyter-widgets for notebook rendering directly instead of all the hacky solutions where a VTK render window is exported/serialized for VTKjs, X3D, or K3D.

from pyvista-support.

GuillaumeFavelier avatar GuillaumeFavelier commented on June 19, 2024 1

After more investigation I found that this version of plot_scene_1() is way simpler and doesn't require notebook_show() or any unnecessary tweaks anymore:

def plot_scene_1():
    from IPython.display import display
    S = pv.Sphere()
    plotter = pv.Plotter()
    plotter.add_mesh(S, color='white')
    disp = plotter.show(use_panel=True, auto_close=False)
    display(disp)
plot_scene_1()

from pyvista-support.

GuillaumeFavelier avatar GuillaumeFavelier commented on June 19, 2024

Actually if I modify plot_scene_1() like the following, it is displayed automatically:

def plot_scene_1():
    S = pv.Sphere()
    plotter = pv.Plotter()
    plotter.add_mesh(S)
    return plotter.show()
plot_scene_1()

So I work on integrating this idea in mne-python. Please don't hesitate to tell me if you know any way to do it better.

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

@GuillaumeFavelier: the plotter.show() call is actually returning a panel.pane.vtk.VTK object that can be displayed in the Jupyter cell output. Calling plotter.show() and not having its result be the cell's output will result in the panel-based interactive rendering not be shown.

Screen Shot 2019-06-08 at 5 53 29 PM

I expect this behavior... however this might be considered a bug as a user might expect that any call to .show() will show the renderer. Also, this is inconsistent with a the static screenshot display in Jupyter notebooks (which returns None and displays the screenshot without it being the cells output):

from pyvista import examples
import pyvista as pv

mesh = examples.download_st_helens().warp_by_scalar()

plotter = pv.Plotter()
plotter.add_mesh(mesh)
output = plotter.show(use_panel=False)

Perhaps we need to collaborate with the panel developers to see if there is a way to display a panel object without it being a cell's output?

from pyvista-support.

GuillaumeFavelier avatar GuillaumeFavelier commented on June 19, 2024

Many thanks for the detailed explanations @banesullivan, now I understand better how it works and I think I can manage with this solution for now. Although I had to rely on the part of code detecting if the script is executed inside a notebook.

Perhaps we need to collaborate with the panel developers to see if there is a way to display a panel object without it being a cell's output?

That would wonderful of course!

from pyvista-support.

banesullivan avatar banesullivan commented on June 19, 2024

Although I had to rely on the part of code detecting if the script is executed inside a notebook.

That's strange, what exactly do you mean? I thought I had the panel code to only run if the code is being executed from a Jupyter notebook.

from pyvista-support.

GuillaumeFavelier avatar GuillaumeFavelier commented on June 19, 2024

Actually after some more research I found a way to force panel to show the pane thanks to the show_server() function:

image

So I used the following function:

def notebook_show(disp, notebook_url="localhost:8888", port=0):
    from panel.viewable import show_server
    show_server(disp, notebook_url, port)

Do you think there would be a way to integrate such a feature in PyVista @banesullivan ? Eventually, I can open a discussion with the Panel developers to find a better/cleaner solution just in case.

from pyvista-support.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.