File size: 1,178 Bytes
1280fd8
913507e
 
1280fd8
 
 
 
 
 
 
 
 
 
 
 
 
b93d6c3
1280fd8
 
 
913507e
1280fd8
 
 
 
 
 
 
 
 
 
 
913507e
1280fd8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Ejemplo usando st.bokeh_chart en lugar de st.components.v1.html
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, HoverTool
import streamlit as st
import numpy as np
import random

# Generar datos
N = 10
x = np.random.rand(N)
y = np.random.rand(N)

red_image = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAF/wK+bNykAAAAAElFTkSuQmCC"
blue_image = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mN8/f8/AwAI/AL+fB/9AAAAAElFTkSuQmCC"
images = [random.choice([red_image, blue_image]) for _ in range(N)]
labels = ["subset1" if img == red_image else "subset2" for img in images]

source = ColumnDataSource(data=dict(x=x, y=y, img=images, label=labels))
p = figure(title="Interactive Plot with Hover Images", tools="hover", width=600, height=600)
p.scatter('x', 'y', size=15, source=source, fill_color="navy", alpha=0.5)

hover = p.select_one(HoverTool)
hover.tooltips = """
<div>
  <div>
      <span style="font-size: 12px; font-weight: bold;">Label: @label</span>
  </div>
  <div>
      <img src="@img" alt="Image" style="width:100px;"/>
  </div>
</div>
"""

st.bokeh_chart(p)