0

I'm working on an interactive graph. One of the options is to select the number of rooms for a house. Right now, if you input any number above 5 in the n_rooms argument, the graph will always show data for houses that have 5 or more rooms. So I constructed this

n_rooms = widgets.IntSlider(
    min=1,
    max=5,
    description='number of rooms:',
    layout=Layout(width='30%'),
    style=style,
    disabled=False)

The thing is, this will show a slider that goes from 1 to 5. The only thing I want to change is that instead of showing '5', it shows '5 or more'. Is there any way to do this? Thanks

Juan C
  • 5,846
  • 2
  • 17
  • 51

2 Answers2

0

Use a selection slider to use both integers and strings in sliders.

num_rooms = widgets.SelectionSlider(
options=['1', '2', '3', '4', '5 or more'],
value='1',
description='number of rooms:',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True   )
Vishma Dias
  • 630
  • 6
  • 11
0

In my case (mostly displaying scientific data) it is helpful to define a Text widget and use it together with the Slider. You just have to set readout=False and use a HBox. For example, I have some field strengths stored in intensities:

fs = IntSlider(
        description='fs: ',
        value=0, min=0, max=len(ints)-1,
        readout=False
    )
fs_text = Text(value=f'{ints[0]:.1f}V/nm', description='', layout=Layout(width='80px'))

# ...
# do some updates
# ...

HBox([fs, fs_text])

In this case you are free to do whatever you want with the text of Text in your update function.

TheIdealis
  • 707
  • 5
  • 13