marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.02k stars 264 forks source link

supported by streamlit? #588

Open r-matsuzaka opened 2 years ago

r-matsuzaka commented 2 years ago

Hi. I want to use this feature by streamlit. Is this usage supported?

marcomusy commented 2 years ago

Hi, thanks for drawing my attention to streamlit which looks absolutely fantastic! at the minute this is not supported but I would love to explore the possibilities.

r-matsuzaka commented 2 years ago

Thank you for your response! I am glad to hear that.

At the same time, I am now asking about it to streamlit community. https://github.com/streamlit/streamlit/issues/4366

r-matsuzaka commented 2 years ago

I am not sure this feature belongs to vedo or streamlit.

marcomusy commented 2 years ago

as i understand it should probably belong to vedo.. I hope i can play a bit with it over the weekend

r-matsuzaka commented 2 years ago

streamlit is very user friendly design. If you are familiar with matplot lib, then you just need to prepare place holder and pass fig object to it. Tutorial is useful.

marcomusy commented 2 years ago

My very first try at it:

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

data = vedo.Volume(vedo.dataurl+'embryo.tif').imagedata()
#data = vedo.Sphere().scale(100).polydata()

#print(type(data))
#vedo.show(data, interactive=True)

view_width = 800
view_height = 800

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

Run by:

streamlit run myscript.py

Screenshot from 2022-02-10 18-20-38

for some reason I cannot visualise the polygonal mesh (commented out) but that's maybe due to some problems with the itkwidgets... I guess that since it needs a raw html string it can work with k3d too but I'm not sure how to do it.. @artur-trzesiok

r-matsuzaka commented 2 years ago

Wow. Nice!

r-matsuzaka commented 2 years ago

I have never thought that we can use components method to incorporate figure. I will try it the same way.