ipywidgets:
more buttons
Usually code runs in your notebook because a cell is being run. What if instead it is triggered by a user interface element? It might be a better discovery tool or a better method for rapid prototyping. This is what the ipywidgets library tries to enable.
Notes
Let's look at the code below.
import numpy as np
import matplotlib.pylab as plt
import ipywidgets as widgets
button = widgets.Button(description="Click Me!")
output = widgets.Output()
def on_button_clicked(b):
r = np.random.normal(0, 1, 1)
with output:
output.clear_output()
x1 = np.random.normal(r, 1.0, 1_000_000)
plt.hist(x1, bins=30, label="standard", alpha=0.6)
plt.title(f"r={r[0]}")
plt.show()
button.on_click(on_button_clicked)
widgets.HBox([button, output])
Given that the button
is defined, you're totally free
to re-use it elsewhere!
Feedback? See an issue? Something unclear? Feel free to mention it here.
If you want to be kept up to date, consider signing up for the newsletter.