# Action Button#

import param
import panel as pn

pn.extension(sizing_mode="stretch_width")


## param.Action Example#

This example demonstrates how to use param.Action to trigger an update in a method that depends on that parameter. Actions can trigger any function, but if we simply want to trigger a method that depends on that action, then we can define a small lambda function that triggers the parameter explicitly.

class ActionExample(param.Parameterized):
"""
Demonstrates how to use param.Action to trigger an update.
"""

number = param.Integer(default=0)

@param.depends('action')
def get_number(self):
self.number += 1
return self.number

action_example = ActionExample()
component = pn.Column(
pn.Row(
pn.Column(pn.panel(action_example, show_name=False, margin=0, widgets={"action": {"button_type": "primary"}, "number": {"disabled": True}}),
'**Click the button** to trigger an update in the output.'),
pn.panel(action_example.get_number, width=300), max_width=600)
)
component


## App#

Lets wrap it into nice template that can be served via panel serve action_button.ipynb

pn.template.FastListTemplate(
site="Panel", title="param.Action Example",
main=[
"This example demonstrates **how to use param.Action to trigger an update** in a method that depends on that parameter.\n\nActions can trigger any function, but if we simply want to trigger a method that depends on that action, then we can define a small lambda function that triggers the parameter explicitly.",
component,
]
).servable();

This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.