Streamlit PyVista
A Streamlit component that allow support for new pyvista viewer backend : Trame.
Installation instructions
pip install streamlit-pyvista
Usage Instructions
import streamlit as st
from streamlit_pyvista.mesh_viewer_component import MeshViewerComponent
def main():
st.title("Simple Streamlit App With Pyvista Viewer")
mesh_viewer = MeshViewerComponent("assets/plate_hole.vtu")
mesh_viewer2 = MeshViewerComponent("assets/plate_hole.vtu")
mesh_viewer.show()
mesh_viewer2.show()
if __name__ == "__main__":
main()
Note that instead of a file path it's also possible to pass an array of paths to display a sequence of files. Only local file paths are supported.
This viewer leverage the capabilities of the new pyvista backend Trame, beyond the nice design revamp,
it also supports remote rendering through trame's websocket based rendering.
Mesh sequences and memory bounds
When an array of paths is passed, the viewer loads the sequence lazily to keep the server memory bounded, whatever the number of frames:
- Only
PRELOADED_FRAMESframes (20 by default, see theSTREAMLIT_PYVISTA_PRELOADED_FRAMESenvironment variable) are loaded upfront, spread evenly over the whole sequence. The progress bar covers this pre-loading (e.g. "Loading mesh 3/20"). - The play button cycles through the pre-loaded frames only, so the animation is a set of jumps between evenly spread frames and never stalls on a load.
- Every frame stays reachable: navigating to a non pre-loaded frame (slider drag, stepping) loads it in the background while a spinner is shown, then displays it. Decimated versions are cached on disk and shared between users, so a frame is only decimated once per machine.
- At most
PRELOADED_FRAMES + 1meshes are kept in memory: frames loaded on demand are unloaded least-recently-used first. Unloaded frames are read back from the cache (without re-decimation) when visited again, which keeps memory roughlyO(PRELOADED_FRAMES)per viewer.
The scalar bar bounds are computed over the loaded frames only; with the default pre-loading they cover 20 frames spread evenly over the sequence.
Decimation
For large meshes (more than 6000 cells by default, see the STREAMLIT_PYVISTA_DECIMATION_THRESHOLD environment
variable), the viewer automatically computes a decimated version of the mesh ("thumbnail") that is displayed by
default to keep the interface fast. A checkbox in the viewer lets you switch to the original resolution: the full
mesh is then loaded in the background while a spinner is shown, so the interface never freezes.
Decimation relies on pyvista.PolyData.decimate_pro (vtkDecimatePro), which is fast and robust on all mesh types,
including large flat (planar) surface meshes. The deprecated pyvista.PolyData.decimate (vtkQuadricDecimation) is
intentionally not used: as of vtk 9.7.1 it can hang forever on flat meshes while flooding the log with "Unable to
factor linear system" warnings. vtk warnings are additionally muted while a mesh is being processed so that no
filter can flood the logs.
While the server is busy (loading meshes, decimating, computing scalar bounds) a spinner is displayed on top of the plotter. During the pre-loading of a sequence of files, this spinner turns into a progress bar showing e.g. "Loading mesh 3/20" (see "Mesh sequences and memory bounds" above).
Composite meshes
Some formats (e.g. Exodus) are read by pyvista as a pv.MultiBlock composite holding the element block(s) plus empty
groups for the various sets (side sets, node sets, ...). Mesh files are therefore normalized on read: composites are
flattened into a single UnstructuredGrid containing the data of all non-empty blocks, so the rest of the package
(decimation, field selectors, scalar bounds) can treat every mesh uniformly.
Field selectors
The scalar field dropdown (and the warp field dropdown) of the viewer list only the fields a user would want to look
at: internal vtk arrays and the bookkeeping arrays generated by file format readers (e.g. the Exodus reader's
ObjectId, ElementBlockIds, QA_Records, Title, Info_Records) are filtered out. The filter lives in
filter_field_options (streamlit_pyvista/trame_viewers/trame_backend.py), backed by the
READER_METADATA_ARRAY_NAMES set.
Package documentation
You can find the automatic documentation generated with sphinx here
Workflow overview
This package has 3 different components:
- The Streamlit component
- The Trame viewers
- A "Server manager"
Streamlit component
This pyvista new backend requires now to have its own server for each instance of a pyvista plotter. This means that the streamlit component can be as simple as an iframe and displayed in the app and can use a simple api to communicate with the trame server and the server manager
Trame viewers
The Trame viewers are the servers that are embedded in the streamlit app, it has exposed api endpoints that allow the component to communicate with the server for action such as loading a mesh in the viewer.
Server manager
As said earlier, the trame viewers can only display one plotter at a time which means that if we want to display multiple plotters we need multiple servers. The job of the Server manager is to control how many trame viewers exists, if they need to killed or if they can be reused for other viewers
Workflow
These 3 components interact the following manner:
- A
MeshViewerComponentis created and notify aServerManagerthat it needs a viewer. - The
ServerManagerlook if he have idling trame viewer anf if not, it start a new server. - The
ServerManagerspecify the endpoints of the server that can be used to theMeshViewerComponent - The
MeshViewerComponentdirectly communicate with the api of the trame viewer via the endpoints specified by theServerManager
Metadata
Release files for streamlit-pyvista 0.0.25
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streamlit_pyvista-0.0.25.tar.gz | 4.9 MB | Without provenance | Details for streamlit_pyvista-0.0.25.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamlit_pyvista-0.0.25-py3-none-any.whl | Python 3 | none | any | Details for streamlit_pyvista-0.0.25-py3-none-any.whl |
Total release size: 5.0 MB
Release files / streamlit_pyvista-0.0.25.tar.gz
| Download URL | streamlit_pyvista-0.0.25.tar.gz |
|---|---|
| Size | 4.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b3f7f870a6b1569f07b1ed4e70721bbbd47cf29f23a00f9a77c72e3f1f9df578
|
|
BLAKE2b-256 checksum How to use checksums |
b66091e02276a5c24868a0c80014e7a45d9684aa865c5228d49066eb2672c355
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / streamlit_pyvista-0.0.25-py3-none-any.whl
| Download URL | streamlit_pyvista-0.0.25-py3-none-any.whl |
|---|---|
| Size | 67.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
40f9fa271ec1af5f423f90a7dafe6967077f959aed3d6747063a33e5b756f6e4
|
|
BLAKE2b-256 checksum How to use checksums |
5568b17cc7ef9a25f76ba4f32d228ee6a5109e0dbd6d40319e9961468472f0f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for streamlit-pyvista 0.0.25
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.