Jupyter widget notebook with two sliders, making a HTTP POST request on change
This extended version of Jupyter Widget notebook with interactive IntSlider making a HTTP POST request features two sliders instead of one.
import ipywidgets as widgets
import httpx
from IPython.display import display
# Define the slider widget
delaySlider = widgets.IntSlider(
value=450, # Initial value
min=0, # Minimum value
max=2000, # Maximum value
step=1, # Step size
description='Delay:'
)
lengthSlider = widgets.IntSlider(
value=20*10, # Initial value
min=0, # Minimum value
max=40*10, # Maximum value
step=1, # Step size
description='Length:'
)
# Define a function to handle slider changes
def on_slider_change(change):
# Define the API URL with the slider value
httpx.post("http://10.1.2.3/api/configure", json={"channels":[{
"channel": 0,
"delay": delaySlider.value,
"length": lengthSlider.value,
}]})
# Attach the slider change handler to the slider widget
delaySlider.observe(on_slider_change, names='value')
lengthSlider.observe(on_slider_change, names='value')
# Display the slider widget in the notebook
display(widgets.Box(children=[delaySlider, lengthSlider]))