from bokeh.models import CustomJSHover
import pandas as pd
import hvplot.pandas
import panel as pn
import datashader as ds
import holoviews as hv
from holoviews.operation.datashader import rasterize, dynspread
def transform(df):
if not len(df):
return df
return df.select_dtypes("number").mean(axis=0).to_frame().T
df = pd.DataFrame(
{
"lon": [-86.75, -86.75, -86.25, -86.25],
"lat": [33.75, 34.0, 34.49, 34.5],
"population": [100, 200, 300, 400],
"R": ["A", "B", "A", "B"],
}
)
highlighter = hd.inspect_points.instance(
streams=[hv.streams.PointerXY], transform=transform
)
p = dynspread(
datashade(
hv.Points(df, vdims=["population", "R"]),
aggregator=ds.max("population"),
)
)
highlighter(p).opts(
color="red", tools=["hover"], marker="square", size=10, fill_alpha=0
) * p