GithubHelp home page GithubHelp logo

edsaac / stpyvista Goto Github PK

View Code? Open in Web Editor NEW
59.0 3.0 4.0 5.29 MB

🧊 Show pyvista 3D visualizations in streamlit

Home Page: https://stpyvista.streamlit.app

License: GNU General Public License v3.0

Python 1.25% HTML 97.87% JavaScript 0.83% CSS 0.05%
python visualization pyvista streamlit

stpyvista's Issues

Problem with PolyData and add_point_labels

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:

  1. 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.

  2. 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

Usage example not working

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

output error

A new error occur. it can not show my VTk, just a output word.
image.
image

RuntimeError: "There is no current event loop" when running streamlit app with stpyvista

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:

  • python version: 3.9.13
  • pyvista version: 0.42.0
  • Streamlit version: 1.30.0
  • stpyvista version: 0.0.14

Legend not shown

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:

image

xserver

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

Camera.zoom() not working

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)

TypeError:unsupported operand type(s) for |: 'type' and 'NoneType'

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

NSInternalInconsistencyException Error

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.

Stpyvista not displaying .stl file when deployed on community cloud

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.

67bf4028e7fdf36583894ae40936b65630eb89e3

But when I deploy it with recommended packages It doesn’t display anything, see snip below

dad014cdd37eaa5394dcf9c494a1251563d8a000

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

Coloration abnormalities

I want to color my VTK image.If I key "plotter.show()", it did great.But in stpyvista , there is an abnormality in the color.

image
image

stpyvista display blank region in browser (tested with provided examples)

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".

localhost-1679643230547.log

Thank you very much for your help on this.

Import issues: AttributeError: type object 'DataImage' has no attribute '_instance_inits'

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.

problem with use stpyvista in streamlit cloud

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:

Error importing stpyvista

Detailed 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!


Interactions

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.