Action button

Download this notebook from GitHub (right-click to download).


In [ ]:
import param
import panel as pn

pn.extension()

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 we can define a small lambda function that triggers the parameter explicitly.

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

    number = param.Number(default=0)
    
    action = param.Action(lambda x: x.param.trigger('action'), label='Click here!')
        
    @param.depends('action')
    def get_number(self):
        return self.number
    
action_example = ActionExample()
pn.Column(
    '# param.Action Example',
    pn.Row(
        pn.Column(pn.panel(action_example.param, show_labels=False, show_name=False, margin=0),
            'Click the button to trigger an update in the output.'),
        pn.WidgetBox(action_example.get_number, width=300))
).servable()

Download this notebook from GitHub (right-click to download).