Ipywidgets: FloatSlider with very small values

Created on 3 Dec 2015  路  15Comments  路  Source: jupyter-widgets/ipywidgets

The float widget does not display properly and is not able to "slide" (except to min and max values) if the values are very small:

order = 1e-8
widgets.FloatSlider(min=1.*order, max =5.*order, step= 0.05*order, value = 2.*order)

It looks like the smallest step value is hard-coded, however with a quick look I was not able to find anything of sort

bug

Most helpful comment

A workaround is to use the Selection slider and to generate the values and labels you want.

from ipywidgets import SelectionSlider
values=[i*10**-8 for i in range(101)]
SelectionSlider(options=[("%g"%i,i) for i in values])

The much more invasive change is to use a different slider implementation, like mentioned above.

All 15 comments

1e-6 also doesn't work. I think this may be because of rounding to get nice displayed numbers in the slider.

I think this is the problem: https://github.com/jquery/jquery-ui/blob/800d76ac17345b6016f3d067b41a757ebd2c9bb8/ui/widgets/slider.js#L540. IIRC, to get around this in Sage, we compute the transformation between integer indices and the values for the sliders and then always use integer indices for the slider, but display the corresponding float value from the range. In fact, we go one step further and precompute the slider values on the server, so that the slider is not limited to float precision, or even to floats. This lets us have sliders for Likert scales, crazy-small floats (precision 1e-1000, for example), etc.

This depends on getting rid of jqueryui for the sliders: https://github.com/jupyter-widgets/ipywidgets/issues/630

This is a real pain in the neck. Is there any updates or ideas on how to resolve this issue?

A workaround is to use the Selection slider and to generate the values and labels you want.

from ipywidgets import SelectionSlider
values=[i*10**-8 for i in range(101)]
SelectionSlider(options=[("%g"%i,i) for i in values])

The much more invasive change is to use a different slider implementation, like mentioned above.

Thanks for the quick response, this definitely does the trick for me. The work you guys are doing is truly inspirational, looking forward to seeing future developments :1st_place_medal:

@jasongrout your solution worked well thank you.
I don't know if this is the right place to ask but I can't seem to find the way to use properly the input next to the SelectionSlider (I would like to edit the values directly inside of it).

I faced this issue with the jqueryui sliders two years ago and could fix it.

A way to fix this issue in ipywidgets is to scale the values in the slider widget.

What I mean is that we always have an internal jqueryui slider with values in an acceptable range, say 0 to 100. And properly scale the readout value, values that are get and values that are set in the actual given range.

If you are ok with this fix @jasongrout I can try to implement it.

I tried the noUiSlider and it does not seem to work with very low values. Values are simply equal to 0 on change events.
I'll try to scale the slider value on my local project, and open a PR on ipywidgets later if I am able to fix it.

I tried the noUiSlider and it does not seem to work with very low values

I am actually wrong, it works perfectly. noUiSlider looks really good and is a good candidate for the base slider replacement.

This has been fixed thanks for @ibdafna 's new implementation of the slider!

I am closing, but feel free to reopen if the issue reappears.

slider

I updated ipywidgets version to the last version (v7.6.3), but still having the problem with this code:
import ipywidgets
ipywidgets.FloatSlider( value=0, min=0, max=0.00008, step = 0.000001, readout_format='.6f')
What could be the issue?

This fix should be included in v8

Ok, thank you so much for your very quick response :)

Sure :) I am also waiting for this fix!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kebwi picture kebwi  路  6Comments

andymcarter picture andymcarter  路  6Comments

pleabargain picture pleabargain  路  5Comments

hangyao picture hangyao  路  6Comments

fses91 picture fses91  路  6Comments