Is it possible plot 3D Mesh file or to add the VTK/ Pyvista window inline streamlit?

I find Streamlit impressive. Outstanding work!

I have a 3d mesh file. I am able to plot the 3d mesh file using pyvista library, ITK widgets, and see it in the notebook interactively.

I would like to show this 3D plot in Streamlit interactively. Is it possible to do it? If there is an example, it would be very helpful.

Kind regards,
Hemanand

Hello @Hems, welcome to the community.

With Components coming really soon, which will enable you to run arbitrary HTML/JS code in Streamlit, we should be able to replicate part of ITKWidget’s code, which is passing a JS representation or file upload of your mesh read through Pyvista into itk-vtk-viewer / vtk.js to visualize it in Streamlit.

I believe that’s an excellent example off custom component where you can have a quick prototype working, if you want to try it out when it’s live :wink:

Fanilo

Hi,
Thanks for pointing me towards the right direction. It is very interesting. I’ll try it.

Regards,
Hems

Well now it’s out :slight_smile:

Hey @Hems, I am curious if you got the pyvista/vtk component to work! Wouldn’t want to re-invent the wheel :stuck_out_tongue:

Hi @nickvazz , Unfortunately, I could not find the time to make it. Please let me know if you create it :slightly_smiling_face: . Good luck!

Hello
a code snippet working for me with itkwidgets.

import vtk
from itkwidgets import view
from ipywidgets import embed
import streamlit.components.v1 as components

nifti_reader = vtk.vtkNIFTIImageReader()
reader.SetFileName(PATH-TO-LOCAL-NIFTI-FILE)
reader.Update()


view_width = 800
view_height = 600

snippet = embed.embed_snippet(views=view(reader.GetOutput()))
html = embed.html_template.format(title="", snippet=snippet)
components.html(html, width=view_width, height=view_height)

Hope that could help :wink:

Thank you very much! It worked for me

In case someone stumbles upon this post, there is the stpyvista component to render PyVista plotters in streamlit:

stpyvista_intro_crop

stpyvista examples and documentation


Github Repo Check it at PyPI