A Streamlit component for NiiVue neuroimaging viewer
Project description
NiiVue Streamlit Component
A modern Streamlit component for visualizing neuroimaging data using NiiVue, built with TypeScript, Preact, and Vite.
๐ Quick Start
Simple Installation & Usage
-
Install the component:
pip install --index-url https://test.pypi.org/simple/ --no-deps niivue-streamlit
-
Use in your Streamlit app:
import streamlit as st from niivue_component import niivue_viewer uploaded_file = st.file_uploader("Choose a NIFTI file", type=["nii", "nii.gz"]) if uploaded_file is not None: result = niivue_viewer( nifti_data=uploaded_file.getvalue(), filename=uploaded_file.name, height=700 ) # Handle click events if result: st.write(f"Clicked voxel: {result['voxel']}, Value: {result['value']}")
โจ Features
- ๐จ Two Component Modes:
StyledViewer: Full-featured viewer with interactive menu and controlsUnstyledCanvas: Minimal canvas-only viewer for embedding
- ๐ Multiple View Modes:
- Axial, Coronal, Sagittal slices
- 3D render view
- Multiplanar view with render
- ๐ Advanced Capabilities:
- Multiple overlay images with custom colormaps
- Configurable display settings (crosshair, radiological convention, colorbar, interpolation)
- Bidirectional communication (click events from viewer to Python)
- DICOM support
๐ Advanced Usage
With Overlays
from niivue_component import niivue_viewer
result = niivue_viewer(
nifti_data=main_image_bytes,
filename="brain.nii.gz",
overlays=[
{
"data": overlay_bytes,
"name": "activation.nii.gz",
"colormap": "hot",
"opacity": 0.7
}
],
view_mode="multiplanar",
styled=True,
settings={
"crosshair": True,
"radiological": False,
"colorbar": True,
"interpolation": True
},
height=800
)
Minimal Viewer (No Menu)
# Perfect for embedding in complex layouts
result = niivue_viewer(
nifti_data=image_bytes,
filename="scan.nii",
styled=False, # Hide menu
view_mode="axial",
height=400
)
๐ API Reference
niivue_viewer()
Parameters:
nifti_data(bytes, optional): Raw NIFTI file datafilename(str): Displayed filenameoverlays(list[dict], optional): Overlay images listdata(bytes): Overlay dataname(str): Overlay namecolormap(str): Colormap (default: 'red')opacity(float): 0-1 (default: 0.5)
height(int): Height in pixels (default: 600)view_mode(str): 'axial', 'coronal', 'sagittal', '3d', 'multiplanar' (default)styled(bool): Show menu (default: True)settings(dict, optional):crosshair(bool): default Trueradiological(bool): default Falsecolorbar(bool): default Falseinterpolation(bool): default True
key(str, optional): Component key
Returns:
dict or None with click event data:
type: 'voxel_click'voxel: [x, y, z]mm: [x, y, z]value: floatfilename: str
๐ ๏ธ Development
Frontend Development
Built with modern web technologies:
- Vite: Fast build tool
- TypeScript: Type safety
- Preact: Lightweight React
- Tailwind CSS: Styling
- niivue-react: Shared components
cd niivue_component/frontend
# Start dev server (requires backend running)
pnpm dev
# Build for production
pnpm build
Backend Development
Toggle dev/production in __init__.py:
_RELEASE = False # Dev mode: localhost:3001
_RELEASE = True # Prod mode: built files
Running Examples
# Simple example
streamlit run app.py
# Advanced example with all features
streamlit run app_advanced.py
๐ Supported Formats
- NIFTI (.nii, .nii.gz)
- DICOM (.dcm)
- MINC (.mnc, .mnc.gz)
- MHA/MHD
- NRRD
- MGH/MGZ
๐๏ธ Architecture
niivue_component/
โโโ __init__.py # Python API
โโโ frontend/
โ โโโ src/
โ โ โโโ components/
โ โ โ โโโ StyledViewer.tsx
โ โ โ โโโ UnstyledCanvas.tsx
โ โ โโโ types.ts
โ โ โโโ utils.ts
โ โโโ vite.config.ts
โ โโโ package.json
โโโ build/ # Compiled assets (generated, not in git)
๐ง Building the Component
The build files are not committed to git. To build the component locally:
cd niivue_component/frontend
pnpm install
pnpm build
This generates the build/ directory with compiled assets that are included in the Python package during distribution.
๐ License
BSD-2-Clause
๐ Credits
Built on top of:
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file niivue_streamlit-0.2.2b4.tar.gz.
File metadata
- Download URL: niivue_streamlit-0.2.2b4.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d3001d1290fc6fdddb560b5b2b660f9d84ae5522a2f242f76d264fd1938f277
|
|
| MD5 |
e6a29d0af7ce50b503310e1244834e3d
|
|
| BLAKE2b-256 |
a796738cfb250406b1dd05ea019de64694e2d696036f2679b52bd638c2b89c74
|
File details
Details for the file niivue_streamlit-0.2.2b4-py3-none-any.whl.
File metadata
- Download URL: niivue_streamlit-0.2.2b4-py3-none-any.whl
- Upload date:
- Size: 1.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff400215ec7130436688aacae44b3c9e320cc3ac5f1b3b2f2876c8f3aebd975a
|
|
| MD5 |
098910762474841c277785f83d19a6ac
|
|
| BLAKE2b-256 |
1f27a8d945f7e1bb4d794544e8680a97990f0ec0619eba0e2ab4b34c4c19f852
|