Skip to content

Instantly share code, notes, and snippets.

@jsignell
Last active April 19, 2019 19:09
Show Gist options
  • Save jsignell/f6c83eb33dcdb42c5a922f452bc7dfc2 to your computer and use it in GitHub Desktop.
Save jsignell/f6c83eb33dcdb42c5a922f452bc7dfc2 to your computer and use it in GitHub Desktop.
import panel as pn
pn.extension()
labels = [t[0] + t[1] + t[2] for t in zip('abcdefghijklmnopqrstuvwxyz','bcdefghijklmnopqrstuvwxyza', 'cdefghijklmnopqrstuvwxyzab')]
options = dict(zip(labels, range(len(labels))))
multi = pn.widgets.MultiSelect(options=options)
sort = pn.widgets.Button(name='▼', width=40)
filt = pn.widgets.AutocompleteInput(options=list(options.keys()), placeholder='Filter')
sort.jslink(multi, code={'clicks': """
source.label = source.clicks % 2 ? '▼' : '▲';
target.options = source.clicks % 2 ? target.options.sort() : target.options.reverse();
console.log(target.options[0]);
console.log(source.clicks);
"""})
filt.jslink(multi, code={'value': """
target.value = target.options.filter(label => label.includes(source.value));
console.log(target.value);
"""})
result = pn.pane.Str('')
multi.link(result, value='object')
pn.Column(pn.Row(sort, filt, margin=0), multi, result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment