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

1 Like

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

1 Like

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

Regards,
Hems

1 Like

Well now it’s out :slight_smile:

1 Like

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:

1 Like

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!

1 Like

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:

5 Likes

Thank you very much! It worked for me

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.

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

1 Like