edsaac / stpyvista Goto Github PK
View Code? Open in Web Editor NEWπ§ Show pyvista 3D visualizations in streamlit
Home Page: https://stpyvista.streamlit.app
License: GNU General Public License v3.0
π§ Show pyvista 3D visualizations in streamlit
Home Page: https://stpyvista.streamlit.app
License: GNU General Public License v3.0
Love the work you've done! It would be awesome if the plot window could be autosized to the streamlit container width, instead of pegged to a fixed width.
The newest release on here is https://github.com/edsaac/streamlit-PyVista-viewer/releases/tag/V0.0.6, but on pypi it's showing 0.0.7. That release however is missing the changes from d4386cc, which I need. What's causing issues now specifically is the height = height+100,
in line 93 of init.py (too much space around the component).
Hi everyone,
I'm attempting to integrate some three-dimensional visualization examples using PyVista into a Streamlit application. I'm encountering difficulties with two specific examples:
Creating a truss (https://docs.pyvista.org/version/stable/examples/00-load/create-truss#sphx-glr-examples-00-load-create-truss-py) I'm trying to adapt this example to display a truss in a Streamlit application. I have problem with visualization with using PolyData
.
Calculating distance along a spline (https://docs.pyvista.org/version/stable/examples/02-plot/distance-along-spline#sphx-glr-examples-02-plot-distance-along-spline-py) I have problem with visualization when use the add_point_labels
function to label points along a spline.
I would appreciate if someone could offer some advice on resolving these issues and making the examples work in Streamlit.
Thank you in advance for your help!
Domenico
The usage example is not currently working for me. No errors, but the 3D model is not shown.
There is also a deprecation warning: PyVistaDeprecationWarning: pythreejs backend is deprecated and is planned for future removal.
The examples on the page on the Streamlit Community Cloud don't work either anymore: https://stpyvista.streamlit.app/,
Windows 10, Python 3.11, pyvista 0.38.5, stpyvista 0.0.5, streamlit 1.20.0
I am encountering a RuntimeError when attempting to run a Streamlit app that utilizes stpyvista for visualization. I run the example stpyvista code, which is this one:
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(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.add_scalar_bar()
plotter.background_color = 'white'
## Pass a key to avoid re-rendering at each time something changes in the page
stpyvista(plotter, key="pv_cube")
However, when I did run streamlit app.py
, I encounter the following error:
RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'.
Traceback:
File "D:\Python\Python39\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 535, in _run_script
exec(code, module.__dict__)
File "C:\Users\hamid\Downloads\app.py", line 3, in <module>
from stpyvista import stpyvista
File "D:\Python\Python39\lib\site-packages\stpyvista\__init__.py", line 8, in <module>
import panel as pn
File "D:\Python\Python39\lib\site-packages\panel\__init__.py", line 50, in <module>
from . import chat # noqa
File "D:\Python\Python39\lib\site-packages\panel\chat\__init__.py", line 33, in <module>
from .feed import ChatFeed # noqa
File "D:\Python\Python39\lib\site-packages\panel\chat\feed.py", line 25, in <module>
from ..io.resources import CDN_DIST
File "D:\Python\Python39\lib\site-packages\panel\io\__init__.py", line 9, in <module>
from .document import ( # noqa
File "D:\Python\Python39\lib\site-packages\panel\io\document.py", line 47, in <module>
WRITE_LOCK = asyncio.Lock()
File "D:\Python\Python39\lib\asyncio\locks.py", line 81, in __init__
self._loop = events.get_event_loop()
File "D:\Python\Python39\lib\asyncio\events.py", line 642, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
Any guidance on resolving this issue would be greatly appreciated :)
Additional Information:
Adding a legend by making the following changes to the usage example doesn't work, i.e. no legend is visible:
...
## Add mesh to the plotter
plotter.add_mesh(mesh, scalars='myscalar', cmap='bwr', line_width=1, label="cube")
plotter.add_legend()
...
No errors are being shown.
On the other hand, when calling plotter.show()
before st.session_state.model = HTML_stpyvista(plotter)
, the legend is visible in the separate pyvista window:
Hi,
great project. However, i encounter some issues recently using stpyvista.
Locally, it runs well. But when deployed to a server, the 3D model fails to display on the browser on the user end, with the following error:
'this system does not appear to be running an xserver
PyVista will likely segfault when rendering.
Try starting a virtual frame buffer with xvfb, or using
pyvista.start_xvfb()
warnings.warn(
It is strange that some time ago (before update?), the 3D viewer works fine
Hi,
PyVistaDepted and is planned for future removal. pv.set_jupyter_backend('panel')
ValueError: Invalid Jupyter notebook plotting backend "panel".
Use one of the following:
"static", "client", "server", "trame", "none"
Changing the value in camera.zoom()
has no effect.
MWE:
import pyvista as pv
from stpyvista import stpyvista
plotter = pv.Plotter(window_size=[400,400])
mesh = pv.Cube(center=(0,0,0))
plotter.add_mesh(mesh)
plotter.view_isometric()
plotter.camera.zoom(100)
stpyvista(plotter)
import pyvista as pv
import streamlit as st
from stpyvista import stpyvista
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')
## Final touches
plotter.view_isometric()
plotter.background_color = 'white'
## Send to streamlit
stpyvista(plotter, key="pv_cube")
Any guidance on resolving this issue would be greatly appreciated :)
Additional Information:
python version: 3.9.13
pyvista version: 0.43.4
Streamlit version: 1.32.2
stpyvista version: 0.0.14
panel version: 0.13.1
I cloned this repo and tried to run the code via streamlit but keep running into this issue on my Mac:
2023-09-04 11:32:27.017 Python[63562:3191072] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
Streamlit will just disconnect
I tried to do a workaround by using docker but I run into a seg fault.
Hi there,
I have been using @edsaac stpyvista component to provide a visulisation to support an engineering optimisation exercise for a simple retaining wall calculation but I am having issues once deploying to the cloud.
The application runs fine when running locally, see snip below.
But when I deploy it with recommended packages It doesnβt display anything, see snip below
And the code is here β GitHub - TomCarts/L_Unit_Optimisation: Streamlit application for optimising an 'L' shaped retaining wall under global sliding and overturning
Any help really appreciated
Dear developers,
Thanks a lot for this project.
For some reason something go broken recently, and the rendered box does not appear anymore.
The script I used is:
import streamlit as st
import pyvista as pv
from stpyvista import stpyvista
# ipythreejs does not support scalar bars :(
pv.global_theme.show_scalar_bar = False
# 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()
# Pass a key to avoid re-rendering at each time something changes in the page
stpyvista(plotter, key="pv_cube")
The versions of packages are
streamlit 1.20.0
pyvista 0.38.5
stpyvista 0.0.5
stpyvista 0.0.5
pythreejs 2.3.0
ipywidgets 7.7.1
ipython 8.4.0
I also join the log from chrome, showing some complaints about some "widgets".
Thank you very much for your help on this.
Hi,
I have installed stpyvista via pip install stpyvista
without any issues. When I try to import stpyvista in Python from stpyvista import stpyvista
, I get the following error message:
2023-03-14 13:28:03.023 Uncaught app exception
Traceback (most recent call last):
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script
exec(code, module.__dict__)
File "C:\Users\Desktop\stpvista_test.py", line 3, in <module>
from stpyvista import stpyvista
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\stpyvista\__init__.py", line 10, in <module>
pv.set_jupyter_backend('pythreejs')
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\pyvista\jupyter\__init__.py", line 141, in set_jupyter_backend
pyvista.global_theme._jupyter_backend = _validate_jupyter_backend(backend)
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\pyvista\jupyter\__init__.py", line 43, in _validate_jupyter_backend
import pythreejs
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\pythreejs\__init__.py", line 6, in <module>
from .pythreejs import *
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\pythreejs\pythreejs.py", line 20, in <module>
from .core.BufferAttribute import BufferAttribute
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\pythreejs\core\BufferAttribute.py", line 4, in <module>
from .BufferAttribute_autogen import BufferAttribute as BaseBufferAttribute
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\pythreejs\core\BufferAttribute_autogen.py", line 13, in <module>
from ..traits import *
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\pythreejs\traits.py", line 18, in <module>
from ipydatawidgets import DataUnion, NDArrayWidget, shape_constraints
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\ipydatawidgets\__init__.py", line 7, in <module>
from .ndarray import *
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\ipydatawidgets\ndarray\__init__.py", line 7, in <module>
from .media import DataImage
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\ipydatawidgets\ndarray\media.py", line 17, in <module>
class DataImage(DataWidget, DOMWidget):
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\traitlets\traitlets.py", line 958, in __init__
cls.setup_class(classdict)
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\traitlets\traitlets.py", line 981, in setup_class
super().setup_class(classdict)
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\traitlets\traitlets.py", line 973, in setup_class
v.subclass_init(cls)
File "C:\Users\miniconda3\envs\CloudComPy310\lib\site-packages\ipydatawidgets\ndarray\union.py", line 59, in subclass_init
cls._instance_inits.append(self.instance_init)
AttributeError: type object 'DataImage' has no attribute '_instance_inits'
Can someone please help?
FYI: I am using miniconda3 with Python 3.10.
Sure, here is an improved version of your questions in English for a forum:
Hi everyone,
I'm encountering an error when trying to import stpyvista
in my project. Below are the screenshots of the error:
For context, here is my installation file:
Does anyone have any idea how to resolve this issue?
I have python 3.10
Thanks in advance for your help!
Hello,
Is there any way to interact with the component?
i.e. if you click a node, it will return the node number to the python code
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.