import subprocess
import sys
if "google.colab" in sys.modules:
subprocess.run("apt-get update", shell=True, check=True)
subprocess.run("apt-get install -qq xvfb libgl1-mesa-glx", shell=True, check=True)
subprocess.run("pip install pyvista[all] -qq", shell=True, check=True)
import pyvista as pv
# Seems that only static plotting is supported by colab at the moment
pv.global_theme.jupyter_backend = "static"
pv.global_theme.notebook = True
pv.start_xvfb()
else:
%matplotlib inline
from pyvista import set_plot_theme
set_plot_theme("document")
A simple example of how to create a Trame app with a PyVista Plotter.
This example contains the boilerplate code to use anytime you are creating a new Trame application with PyVista.
import pyvista as pv
from pyvista import examples
from pyvista.trame.ui import plotter_ui
from trame.app import get_server
from trame.ui.vuetify3 import SinglePageLayout
pv.OFF_SCREEN = True
server = get_server()
state, ctrl = server.state, server.controller
mesh = examples.load_random_hills()
pl = pv.Plotter()
pl.add_mesh(mesh)
with SinglePageLayout(server) as layout:
with layout.content:
view = plotter_ui(pl)
server.start()
{=html}
<center>
<a target="_blank" href="https://colab.research.google.com/github/pyvista/pyvista-tutorial/blob/gh-pages/notebooks/tutorial/09_trame/a_trame_simple.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/ width="150px">
</a>
</center>