Hi,
I want to display an interactive dendrogram (a tree representing the result of the an hierarchical clustering), such that when i put the cursor over a node β either a leaf of an inner node β I can see some labels corresponding to leaves within the subtree rooted in the node.
What I currently have:
import time
import numpy as np
import streamlit as st
import matplotlib
from matplotlib import pyplot as plt
matplotlib.use(βTkAggβ)progress_bar = st.sidebar.progress(0)
status_text = st.sidebar.empty()import time
import numpy as np
import streamlit as st
import matplotlib
from matplotlib import pyplot as plt
matplotlib.use(βTkAggβ)
random.seed(0)
np.random.seed(0)
progress_bar = st.sidebar.progress(0)
status_text = st.sidebar.empty()from scipy.cluster.hierarchy import linkage, dendrogram
from matplotlib import pyplot as plt
data = np.random.rand(1000,30) - 0.5
labels = [βaβ, βbβ, βcβ, βdβ, βeβ, βfβ," ,βgβ, βhβ, βiβ, βjβ]
Z = linkage(data, optimal_ordering = False, method = βwardβ)
dn = dendrogram(Z, truncate_mode = βlastpβ)
st.pyplot()
print(βHereβ)
progress_bar.empty()Streamlit widgets automatically run the script from top to bottom. Since
this button is not connected to any other logic, it just causes a plain
rerun.
st.button(βRe-runβ)
I want to be able to put the cursor over the leaf corresponding to the label "a"
, and see that label; or put the cursor over the inner node which is the ancestor of the leaves "a", "e", "h"
and "j"
, and see those labels (see image).
Thanks!