🧊 Show 3D visualizations from PyVista in Streamlit
Last updated Jul 1, 2026
105
Stars
5
Forks
11
Issues
+1
Stars/day
Attention Score
74
Language breakdown
No language data available.
▸ Files
click to expand
README
🧊 stpyvista
Show PyVista visualizations in Streamlit.
Take a PyVista plotter object and show it on Streamlit as an interactive-ish component (as in it can be zoomed in/out, moved and rotated, but the visualization state is not returned). It can use either Panel or Trame to export the PyVista plotter to HTML; stpyvista places it within an iframe in Streamlit.
📦 Installation
pip install stpyvista
📚 Demo and documentation
✨ Minimal example
Render a cube
import streamlit as st
import pyvista as pv
from stpyvista import stpyvista
Initialize a plotter object
plotter = pv.Plotter(window_size=[400,400])
Create a mesh with a cube
mesh = pv.Cube()
Add some scalar field associated to the mesh
mesh['my_scalar'] = mesh.points[:, 2] * mesh.points[:, 0]
Add mesh to the plotter
plotter.addmesh(mesh, scalars='myscalar', cmap='bwr')
Final touches
plotter.view_isometric()
plotter.addscalarbar()
plotter.background_color = 'white'
Show in web-app
stpyvista(plotter)
🎈 Deploying to Streamlit Community Cloud
- By default, Community Cloud will run Python 3.14 🎈. Check this on New App → Advanced settings... → Python version.
- Add
stpyvistato therequirements.txtfile. - Install
libgl1-mesa-glx,libosmesa6-devandlibxcursor-devadding them to thepackages.txtfile. - The Community Cloud is a Debian headless machine and VTK will attempt to find a rendering environment (more info). Setting these two environment variables should do the trick:
import os
os.environ["VTKUSEX"] = "OFF" os.environ["VTKDEFAULTOPENGL_WINDOW"] = "vtkOSOpenGLRenderWindow"
🚩 Known issues
- [x]
cadqueryconflicts:cadquerybundles an outdated version ofvtk, which ends up conflicting with thevtkversion thatpyvistarequires. Current solution is to installstpyvistabefore cadquery in a virtual environment. For fixing instructions, check this post on discuss. - [ ]
NSInternalInconsistencyExceptionthrown when running on macOS. Current solution is to deploy using a VM.
🍹 Solved issues
- [x]
RuntimeErrorthrown when running Python 3.9. Upgrading topanel>=1.4.0or using Python 3.10 fixes this. - [x] Buggy colormaps when using
panel==1.4.0. This issue was fixed withpanel==1.4.1. - [x]
cmocean==4.0.1will raise an exception while trying to register its colormaps to matplotlib, making PyVista to crash. This issue was fixed incmocean==4.0.3.
🍏 Also check
- The PyVista project at https://www.pyvista.org/
- Working with Panel and Pyvista https://panel.holoviz.org
- @blackary's blog post on how to build a custom component
- Other stuff from me on https://edsaac.me
🔗 More in this category
