pbmc-subset / app.py
selmanozleyen's picture
Upload folder using huggingface_hub
c534f61 verified
import streamlit as st
from vitessce import VitessceConfig, AnnDataWrapper, ViewType as vt
import json
st.title("Vitessce AnnData-Zarr Explorer")
# 1) Pre‑fill from ?url=… in the browser query string
params = st.query_params
default_url = params.get("url", ["http://localhost:8000/pbmc_subset.zarr"])[0]
zarr_url = st.text_input("Zarr store URL:", default_url)
# 2) Build the VitessceConfig (note schema_version is required)
vc = VitessceConfig(schema_version="1.0.17", name="Dynamic Zarr Viewer")
dataset = (
vc
.add_dataset(name="PBMC 3k")
.add_object(AnnDataWrapper(
# Point this at your Zarr store
adata_store=zarr_url,
# Optional: tell it which obs/var fields to expose as cell sets, embeddings, etc.
obs_set_paths=["obs/leiden"],
obs_set_names=["Leiden"],
obs_embedding_paths=["obsm/X_umap", "obsm/X_pca"],
obs_embedding_names=["UMAP", "PCA"],
obs_feature_matrix_path="X"
))
)
obs = vc.add_view(vt.OBS_SETS, dataset=dataset)
vc.layout(obs)
# 3) Embed the viewer
cfg_json = json.dumps(vc.to_dict(base_url=""))
st.components.v1.html(
f"""
<link
rel="stylesheet"
href="https://unpkg.com/vitessce@latest/dist/css/vitessce.min.css"
/>
<script src="https://unpkg.com/vitessce@latest/dist/js/vitessce.min.js"></script>
<div id="v"></div>
<script>
const config = {cfg_json};
Vitessce.create(document.getElementById("v"), config);
</script>
""",
height=750,
)