JackeyOL
JackeyOL

Reputation: 321

How to include the ipywidgets interact code in my own function

For example, I define my own function "f":

def f(x):
    return x 

and I want to make it interactable, so I wrote another function "F":

from ipywidgets import interact
def F():
    interact(f,x=10)

but it didn't work. Any ideas about how I can adjust my code?

Upvotes: 0

Views: 218

Answers (1)

Max
Max

Reputation: 83

Make sure your calling your function

def f(x):
    return x

def F():
    interact(f, x=10)

F()

will work. Since f is defined in a separate file

from MyFunctions import f

interact(f, x=10);

If you make changes to f then restart the kernel because "This will reset your notebook and remove all variables or methods you've defined"

Upvotes: 1

Related Questions