A Gradio custom component that embeds an interactive PyVista plotter in any Gradio app.
pip install gradio-pyvistaplotterThe following minimal example renders an interactive 3D sphere:
import pyvista as pv
import gradio as gr
from gradio_pyvistaplotter import PyvistaPlotter
plotter = pv.Plotter()
plotter.add_mesh(pv.Sphere(), show_edges=True, color="gold")
with gr.Blocks() as demo:
gr.Markdown("Gradio app with a PyVista plotter")
viewer = PyvistaPlotter(value=plotter)
demo.launch()A more complete example with a mesh loader is available in gradio_pyvistaplotter/demo/app.py.
When using PyvistaPlotter with the standard gr.Blocks.launch() method from gradio, the application cannot be interrupted from the terminal via Ctrl+C. As a workaround, this package provides a custom launch() function that wraps gr.Blocks.launch() with proper signal handling:
import pyvista as pv
import gradio as gr
from gradio_pyvistaplotter import PyvistaPlotter, launch
plotter = pv.Plotter()
plotter.add_mesh(pv.Sphere(), show_edges=True, color="gold")
with gr.Blocks() as demo:
gr.Markdown("Gradio app with a PyVista plotter")
viewer = PyvistaPlotter(value=plotter)
launch(demo) # custom launch with proper signal handling- Currently, two files are written to the tmp directory on each render:
static_viewer.htmlandscene_<id>.vtksz. Investigate whether the HTML can be generated and passed as an in-memory string instead of a file on disk. -
static_viewer.htmlis currently bundled with this package — should it be imported directly fromtrameinstead?