Skip to content

edsaac/stpyvista

Folders and files

NameName
Last commit message
Last commit date

Latest commit

967ed05 Β· Nov 9, 2022

History

58 Commits
Nov 9, 2022
Nov 8, 2022
Nov 6, 2022

Repository files navigation

🧊 stpyvista: Show PyVista 3D visualizations in Streamlit

πŸ’Ύ Source code repository πŸ’Ύ

Streamlit Cloud

Github Repo PyPi version Github tests repo

howto-stpyvista|600x340

This is a simple component that takes a PyVista plotter object and shows it on Streamlit as an interactive element (as in it can be zoomed in/out, moved and rotated, but the visualization state is not returned). It uses PyVista's pythreejs backend and it basically takes the plotter, exports it to HTML and displays that within an iframe.

Installation

pip install stpyvista

Demos

Streamlit App

πŸ“€ Display your own STL file on Streamlit

textures-stpyvista|508x500, 85%

🍞 Physically Based Rendering (PBR)

textures-stpyvista|508x500, 85%


Usage example:

import pyvista as pv
import streamlit as st
from stpyvista import stpyvista

# ipythreejs does not support scalar bars :(
pv.global_theme.show_scalar_bar = False

st.title("A cube")
st.info("""Code adapted from https://docs.pyvista.org/user-guide/jupyter/pythreejs.html#scalars-support""")

## Initialize a plotter object
plotter = pv.Plotter(window_size=[400,400])

## Create a mesh with a cube 
mesh = pv.Cube(center=(0,0,0))

## Add some scalar field associated to the mesh
mesh['myscalar'] = mesh.points[:, 2]*mesh.points[:, 0]

## Add mesh to the plotter
plotter.add_mesh(mesh, scalars='myscalar', cmap='bwr', line_width=1)

## Final touches
plotter.view_isometric()
plotter.background_color = 'white'

## Send to streamlit
stpyvista(plotter, key="pv_cube")

Result:

image|589x500, 50%


Also check: