Streamlit wrapper for Cognite Reveal to view 3D content from Cognite Data Fsion
Project description
Cognite 3D Reveal Streamlit
This is a Streamlit library used to display 3D models within a Streamlit app. It works especially well inside Streamlit in Fusion, but can also be used in standalone Streamlit apps.
How to Install
Install the package by running:
pip install streamlit-cognite-reveal
How to Use
Here's an example app using the library:
import streamlit as st
from reveal import reveal
from reveal.config import RevealConfig, ClippingPlane, StyledNodeCollection, NodeAppearance, DefaultNodeAppearance
from cognite.client import CogniteClient
st.subheader("Cognite Reveal Streamlit example")
client = CogniteClient()
if 'selected_asset_ids' not in st.session_state:
st.session_state['selected_asset_ids'] = [4434005487573186]
# Adding UI to update min/max values for sliders
st.sidebar.subheader('Slicing ')
bounding_box_min = st.session_state.get('bounding_box_min', [0,0,0])
bounding_box_max = st.session_state.get('bounding_box_max', [10, 10, 10])
x_toggle = st.sidebar.checkbox('Enable X Slice', value=False)
if x_toggle:
x_value = st.sidebar.slider('Slice X', step = (bounding_box_max[0]-bounding_box_min[0])/100, min_value=bounding_box_min[0], max_value=bounding_box_max[0], value=bounding_box_min[0])
y_toggle = st.sidebar.checkbox('Enable Y Slice', value=False)
if y_toggle:
y_value = st.sidebar.slider('Slice Y', step = (bounding_box_max[1]-bounding_box_min[1])/100, min_value=bounding_box_min[1], max_value=bounding_box_max[1], value=bounding_box_min[1])
z_toggle = st.sidebar.checkbox('Enable Z Slice', value=False)
if z_toggle:
z_value = st.sidebar.slider('Slice Z', step = (bounding_box_max[2]-bounding_box_min[2])/100, min_value=bounding_box_min[2], max_value=bounding_box_max[2], value=bounding_box_min[2])
# Adding UI to configure StyledNodeCollection
st.sidebar.subheader('Node styling')
render_ghosted = st.sidebar.checkbox('Render Ghosted', value=True)
st.sidebar.write('Configure node styling based on node metadata')
item_type = st.sidebar.text_input('Item Type', value="Cylinder")
color = st.sidebar.color_picker('Color', value='#FF0000')
clipping_planes = []
if x_toggle:
clipping_planes.append(ClippingPlane(
normal=[1, 0, 0],
distance=x_value
))
if y_toggle:
clipping_planes.append(ClippingPlane(
normal=[0, 1, 0],
distance=y_value
))
if z_toggle:
clipping_planes.append(ClippingPlane(
normal=[0, 0, 1],
distance=z_value
))
default_node_appearance = DefaultNodeAppearance.Ghosted if render_ghosted else DefaultNodeAppearance.Default
config = RevealConfig(clipping_planes=clipping_planes,
default_node_appearance=default_node_appearance,
styled_node_collections=[
StyledNodeCollection(
filter_criteria={"Item": {"Type": item_type}},
node_appearance=NodeAppearance(
color=color,
render_ghosted=False
)
)
],
height=500
)
state = reveal(
client=client, scene_external_id="26110700-176d-4b0a-b339-812d5b87d838", scene_space="scene",
config=config, key='reveal_1'
)
st.header("Reveal state:")
st.json(state)
if "lastClickedAsset" in state:
st.session_state['selected_asset_ids'].append(state["lastClickedAsset"])
if "boundingBoxMin" in state:
st.session_state['bounding_box_min'] = state["boundingBoxMin"]
if "boundingBoxMax" in state:
st.session_state['bounding_box_max'] = state["boundingBoxMax"]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file streamlit_cognite_reveal-0.0.10.tar.gz
.
File metadata
- Download URL: streamlit_cognite_reveal-0.0.10.tar.gz
- Upload date:
- Size: 6.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88e99a46025f0418f16c1295b2df7073b7bc8701579a7777be8ee86cd51fc363 |
|
MD5 | 01a8ff30ba840ace9af4751ee4a20b79 |
|
BLAKE2b-256 | 674ab1c59556bb4887eef9f34a9810b737545d9959ed1c925cb34782d033d75b |
File details
Details for the file streamlit_cognite_reveal-0.0.10-py3-none-any.whl
.
File metadata
- Download URL: streamlit_cognite_reveal-0.0.10-py3-none-any.whl
- Upload date:
- Size: 6.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eedb55c1049baa00351cbd6b73853205854631c91c9dfca095035bda1af94a9 |
|
MD5 | 975a2ae0e6a2ea2ff522b92862b662e8 |
|
BLAKE2b-256 | eb574a41eccb67138f24128558ee327eab33deb0b482749354cd64692720cd32 |