{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import param\n",
    "import panel as pn\n",
    "\n",
    "pn.extension()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "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."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class ActionExample(param.Parameterized):\n",
    "    \"\"\"\n",
    "    Demonstrates how to use param.Action to trigger an update.\n",
    "    \"\"\"\n",
    "\n",
    "    number = param.Number(default=0)\n",
    "    \n",
    "    action = param.Action(lambda x: x.param.trigger('action'), label='Click here!')\n",
    "        \n",
    "    @param.depends('action')\n",
    "    def get_number(self):\n",
    "        return self.number\n",
    "    \n",
    "action_example = ActionExample()\n",
    "pn.Column(\n",
    "    '# param.Action Example',\n",
    "    pn.Row(\n",
    "        pn.Column(pn.panel(action_example.param, show_labels=False, show_name=False, margin=0),\n",
    "            'Click the button to trigger an update in the output.'),\n",
    "        pn.WidgetBox(action_example.get_number, width=300))\n",
    ").servable()"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
