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!