On a Jupyter Notebook and using ipywidgets I can create sliders using the compact version
import ipywidgets as ip
def f(x):
print(x)
ip.interact(f, x = (0, 1, 1))
The slider's default value is 0 but I would like to make it 1. How can I do this?
Setting a default value in the function definition should work:
The widget abbreviations (using tuples to request sliders, etc.) only expose a small subset of the options that can be passed to a widget. Default values come from the default value in the function definition if available, or the center of the range if not. If you don't want to change the signature of your existing function to give it a default argument, you have two options to specify the initial value:
Wrap your function in another one that specifies defaults:
instantiate a Widget directly and specify the
value
attribute, instead of relying on the abbreviations: