<jupyter_start><jupyter_text>Running this notebook will read in demo shark data and then create a widget that displays information and mapping locations for a specific shark.<jupyter_code>import pandas as pd
import ipywidgets as widgets
from ipyleaflet import Map, Marker, MarkerCluster

df = pd.read_csv('data/sharks_cleaned.csv')
df.shape
counts = df.name.value_counts().to_dict()
names = {'' : ''}
for name, count in counts.items():
    visible_name = '%s (%s)' % (name, count)
    names[visible_name] = name
    
choices = widgets.Dropdown(options=names)
info = widgets.HTML()
m = Map()
m.shark_layer = None

def on_select(event):
    ### filter df data
    name = event.owner.value
    matches = df[df.name == name]
    ### Pull out basic info
    info.value = ''
    info.value += 'Name: %s<br/>' % name
    info.value += 'Gender: %s<br/>' % matches.iloc[0].gender
    info.value += 'N Hits: %s<br/>' % len(matches)
    info.value += 'First/last seen: %s - %s' % (matches.datetime.min(), matches.datetime.max())
    ### render map
    if m.shark_layer is not None:
        m.remove_layer(m.shark_layer)
        
    m.center = (matches.latitude.mean(), matches.longitude.mean())
    markers = []
    for row in matches.itertuples():
        marker = Marker(location=(row.latitude, row.longitude), draggable=False)
        markers.append(marker)
    cluster = MarkerCluster(markers=markers)
    m.add_layer(cluster)
    m.shark_layer = cluster
      
    
choices.observe(on_select, names='value')

box = widgets.VBox(children=[choices, info, m])
box<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14006309148264984, 'fraction_numerical': 0.0006309148264984228, 'mean_word_length': 3.61046511627907, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '634206', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 543, 'n_tokens_neox': 537, 'n_words': 131, 'path': 'demo_notebooks/5. Visualizing shark data without ipython_blocking.ipynb', 'repo_name': 'gregd33/ipython_blocking', 'size': '1585'}