Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Best method to combine sliders and buttons?

I am trying to combine buttons as sort of a filter for my slider. Is there a way to filter out the data in the array the slider uses for each button selected? Or will I need to create an entirely new slider each time the button is clicked? The slider just uses chronological order and makes things appear on visibility=true/false for each point.

Hi @tophatter,

This might be possible, depending on how you want to filtering to work. Could you share an example of what you have so far, along with a description of what you’d like the buttons to do?

-Jon

Thank you very much for your interest. I am both new to coding and forum posting so I there are any obvious errors I apologize.

#format the slider
stepcounter = []
for i in range(len(new_sort)):
tester = dict(
method = ‘restyle’,
args = [‘visible’, [False] * len(data)],
label=str(new_sort[i].date())
)
#Here in each loop we need to set the proper visability in this section we are building the arrays which are formatted chronologically
tester[‘args’][1][0] = True
holddate=new_sort[i]
for k in range(len(data_by_dates)):
check=sorteddates[k]
if(check>holddate):
stepcounter.append(tester)
break
else:
tester[‘args’][1][k] = True

#Here is where we made the buttons for each of the wells
buttonmaker=[]
buttontemp=dict(
args=[‘visible’, [True] * len(data)],
label=“ALL”,
method=‘restyle’
)
buttonmaker.append(buttontemp)
for wname in range(len(wellnamelist)):
buttontemp= dict(
args=[‘visible’, [False] * len(data)],
label=wellnamelist[wname],
method=‘restyle’
)
for j in range(len(data_by_dates)):
if(wellnamelist[wname]==data_by_dates[j][‘name’] or wellnamelist[3]==data_by_dates[j][‘name’]):
buttontemp[‘args’][1][j]=True
else:
buttontemp[‘args’][1][j]=False
buttonmaker.append(buttontemp)

updatemenus=list([
dict(
type=“buttons”,
buttons=buttonmaker,
),])

sliders = [dict(
active = 0,
currentvalue = {“prefix”: "Date "},
pad = {“l”: 30,“b”:10},
steps =stepcounter,
font=dict(family=“Times New Roman”,color=“white”,size=14),
tickcolor=‘white’,
transition=dict(duration=10,easing=“linear”),
#borderwidth=2,
#bordercolor=‘white’,

)]

After extensive research yesterday I believe I need to either get for familiar with callback functions, but I am unaware if there are any outputs when the slider is moved. The other route is to create a slider for each of the individual button cases. I am modeling some data and are trying to look at individual models as part of a whole on a chronological basis. I am doing this all offline through spyder.

Thank you again
-Jeff

Hi Jeff,

Could you repost your example inside a fenced code block (See https://help.github.com/articles/creating-and-highlighting-code-blocks/), this way the markdown formatting doesn’t mess up the indentation, quotes, etc. Please also make it a full example with imports, data, and figure rendering so that it can be copied into a Jupyter notebook cell and run. Thanks!

-Jon