Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make an ipywidget floatslider with a list of values?

I would like to make an ipywidget floatslider, but passing it a list of values, rather than a range and step. Is there a way to do this, or is making a dropdown widget the only option?

like image 256
Dan Avatar asked Sep 21 '25 07:09

Dan


1 Answers

Woops! You can use SelectionSlider, e.g.:

import ipywidgets as widgets

def test(val):
    print(val)

widgets.interact(test, val=widgets.SelectionSlider(description='value',   options=['1', '50', '300', '7000']))

This widget wasn't available in my ipywidgets 4.0, so I had to upgrade. Also, make sure that afterward you run

jupyter nbextension enable --py --sys-prefix widgetsnbextension

as described in their installation instructions.

like image 55
Dan Avatar answered Sep 22 '25 21:09

Dan