Panel | Tutorial 6 Using Interact

2023/02/18 08:15 AM posted in  Coding Notes   comments
Tags:  #Panel

import panel as pn

from panel.interact import interact, fixed
from panel import widgets

pn.extension()

Basic interact

# Basic Function
def f(x):
    return x

# When you pass this function as the first argument to interact along with an integer keyword argument (x=10), a slider is generated and bound to the function parameter.

interact(f, x=10)


# If you pass True or False, interact will generate a checkbox:

interact(f, x=True)

# interact can also be used as a decorator.
@interact(x=True, y=1.0)
def g(x, y):
    return (x, y)
g

# Fixing arguments using fixed
layout = interact(f, x=10)

pn.Column('**A custom interact layout**', pn.Row(layout[0], layout[1]))

Widget abbreviations

Disabling continuous updates for slider widgets

When interacting with functions which takes a long time to run, realtime feedback can be a burden instead of being helpful.

interact(f, x=(0.0, 20.0, None, 5.5), throttled=True)