We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
The active parameter from Accordions layout does not work properly
Hi everyone !

I tried to use the Accordion layout, but when I tried to open by default another Accordion than the first one, it is impossible. 

The _active_ parameter only works when it is [0]. In the example below setting _active_ to [1] will not open the second Accordion. 

Remarks: 
By setting _toggle=True_, it will open correctly. 
It is also correctly opened when setting _active=[0,1]_.
But despite several attempts it is impossible to open a single index different from 0 without _toggle=True_.  

Here's some code example ( from [https://panel.holoviz.org/reference/layouts/Accordion.html](url) ) :

```
import panel as pn
pn.extension()
from bokeh.plotting import figure

p1 = figure(width=300, height=300, name='Scatter', margin=5)
p1.scatter([0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 2, 1, 0])

p2 = figure(width=300, height=300, name='Line', margin=5)
p2.line([0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 2, 1, 0])

accordion = pn.Accordion(('Scatter', p1), p2, active=[1])
accordion
```

![image](https://user-images.githubusercontent.com/70373646/163144683-c04c29ac-3dc3-41d8-a352-891b6b3ce128.png)


Exemple with _toggle=True_ : 

![image](https://user-images.githubusercontent.com/70373646/163144585-1e5412d4-c96f-490a-9056-abdbab6df40c.png)





--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `panel/layout/accordion.py`
Content:
```
1 import param
2 
3 from bokeh.models import Column as BkColumn, CustomJS
4 
5 from .base import NamedListPanel
6 from .card import Card
7 
8 
9 class Accordion(NamedListPanel):
10     
11     active_header_background = param.String(default='#ccc', doc="""
12         Color for currently active headers.""")
13 
14     active = param.List(default=[], doc="""
15         List of indexes of active cards.""")
16 
17     header_color = param.String(doc="""
18         A valid CSS color to apply to the expand button.""")
19 
20     header_background = param.String(doc="""
21         A valid CSS color for the header background.""")
22 
23     toggle = param.Boolean(default=False, doc="""
24         Whether to toggle between active cards or allow multiple cards""")
25 
26     _bokeh_model = BkColumn
27     
28     _rename = {'active': None, 'active_header_background': None,
29                'header_background': None, 'objects': 'children',
30                'dynamic': None, 'toggle': None, 'header_color': None}
31 
32     _toggle = """
33     for (var child of accordion.children) {
34       if ((child.id !== cb_obj.id) && (child.collapsed == cb_obj.collapsed) && !cb_obj.collapsed) {
35         child.collapsed = !cb_obj.collapsed
36       }
37     }
38     """
39 
40     _synced_properties = [
41         'active_header_background', 'header_background', 'width',
42         'sizing_mode', 'width_policy', 'height_policy', 'header_color'
43     ]
44 
45     def __init__(self, *objects, **params):
46         super().__init__(*objects, **params)
47         self._updating_active = False
48         self.param.watch(self._update_active, ['active'])
49         self.param.watch(self._update_cards, self._synced_properties)
50 
51     def _get_objects(self, model, old_objects, doc, root, comm=None):
52         """
53         Returns new child models for the layout while reusing unchanged
54         models and cleaning up any dropped objects.
55         """
56         from panel.pane.base import RerenderError, panel
57         new_models = []
58         if len(self._names) != len(self):
59             raise ValueError('Accordion names do not match objects, ensure '
60                              'that the Tabs.objects are not modified '
61                              'directly. Found %d names, expected %d.' %
62                              (len(self._names), len(self)))
63         for i, (name, pane) in enumerate(zip(self._names, self)):
64             pane = panel(pane, name=name)
65             self.objects[i] = pane
66 
67         for obj in old_objects:
68             if obj not in self.objects:
69                 self._panels[id(obj)]._cleanup(root)
70 
71         params = {k: v for k, v in self.param.values().items()
72                   if k in self._synced_properties}
73 
74         ref = root.ref['id']
75         current_objects = list(self)
76         for i, (name, pane) in enumerate(zip(self._names, self)):
77             params.update(self._apply_style(i))
78             if id(pane) in self._panels:
79                 card = self._panels[id(pane)]
80             else:
81                 card = Card(
82                     pane, title=name, css_classes=['accordion'],
83                     header_css_classes=['accordion-header'],
84                     margin=self.margin
85                 )
86                 card.param.watch(self._set_active, ['collapsed'])
87                 self._panels[id(pane)] = card
88             card.param.update(**params)
89             if ref in card._models:
90                 panel = card._models[ref][0]
91             else:
92                 try:
93                     panel = card._get_model(doc, root, model, comm)
94                     if self.toggle:
95                         cb = CustomJS(args={'accordion': model}, code=self._toggle)
96                         panel.js_on_change('collapsed', cb)
97                 except RerenderError:
98                     return self._get_objects(model, current_objects[:i], doc, root, comm)
99             new_models.append(panel)
100         self._update_cards()
101         self._update_active()
102         return new_models
103 
104     def _cleanup(self, root):
105         for panel in self._panels.values():
106             panel._cleanup(root)
107         super()._cleanup(root)
108 
109     def _apply_style(self, i):
110         if i == 0:
111             margin = (5, 5, 0, 5)
112         elif i == (len(self)-1):
113             margin = (0, 5, 5, 5)
114         else:
115             margin = (0, 5, 0, 5)
116         return dict(margin=margin, collapsed = i not in self.active)
117 
118     def _set_active(self, *events):
119         if self._updating_active:
120             return
121         self._updating_active = True
122         try:
123             if self.toggle and not events[0].new:
124                 active = [list(self._panels.values()).index(events[0].obj)]
125             else:
126                 active = []
127                 for i, pane in enumerate(self.objects):
128                     if id(pane) not in self._panels:
129                         continue
130                     elif not self._panels[id(pane)].collapsed:
131                         active.append(i)
132             
133             if not self.toggle or active:
134                 self.active = active
135         finally:
136             self._updating_active = False
137 
138     def _update_active(self, *events):
139         if self._updating_active:
140             return
141         self._updating_active = True
142         try:
143             for i, pane in enumerate(self.objects):
144                 if id(pane) not in self._panels:
145                     continue
146                 self._panels[id(pane)].collapsed = i not in self.active
147         finally:
148             self._updating_active = False
149 
150     def _update_cards(self, *events):
151         params = {k: v for k, v in self.param.values().items()
152                   if k in self._synced_properties}
153         for panel in self._panels.values():
154             panel.param.update(**params)
155
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/panel/layout/accordion.py b/panel/layout/accordion.py
--- a/panel/layout/accordion.py
+++ b/panel/layout/accordion.py
@@ -73,6 +73,7 @@
 
         ref = root.ref['id']
         current_objects = list(self)
+        self._updating_active = True
         for i, (name, pane) in enumerate(zip(self._names, self)):
             params.update(self._apply_style(i))
             if id(pane) in self._panels:
@@ -97,6 +98,9 @@
                 except RerenderError:
                     return self._get_objects(model, current_objects[:i], doc, root, comm)
             new_models.append(panel)
+
+        self._updating_active = False
+        self._set_active()
         self._update_cards()
         self._update_active()
         return new_models
@@ -120,7 +124,7 @@
             return
         self._updating_active = True
         try:
-            if self.toggle and not events[0].new:
+            if self.toggle and events and not events[0].new:
                 active = [list(self._panels.values()).index(events[0].obj)]
             else:
                 active = []

{"golden_diff": "diff --git a/panel/layout/accordion.py b/panel/layout/accordion.py\n--- a/panel/layout/accordion.py\n+++ b/panel/layout/accordion.py\n@@ -73,6 +73,7 @@\n \n         ref = root.ref['id']\n         current_objects = list(self)\n+        self._updating_active = True\n         for i, (name, pane) in enumerate(zip(self._names, self)):\n             params.update(self._apply_style(i))\n             if id(pane) in self._panels:\n@@ -97,6 +98,9 @@\n                 except RerenderError:\n                     return self._get_objects(model, current_objects[:i], doc, root, comm)\n             new_models.append(panel)\n+\n+        self._updating_active = False\n+        self._set_active()\n         self._update_cards()\n         self._update_active()\n         return new_models\n@@ -120,7 +124,7 @@\n             return\n         self._updating_active = True\n         try:\n-            if self.toggle and not events[0].new:\n+            if self.toggle and events and not events[0].new:\n                 active = [list(self._panels.values()).index(events[0].obj)]\n             else:\n                 active = []\n", "issue": "The active parameter from Accordions layout does not work properly\nHi everyone !\r\n\r\nI tried to use the Accordion layout, but when I tried to open by default another Accordion than the first one, it is impossible. \r\n\r\nThe _active_ parameter only works when it is [0]. In the example below setting _active_ to [1] will not open the second Accordion. \r\n\r\nRemarks: \r\nBy setting _toggle=True_, it will open correctly. \r\nIt is also correctly opened when setting _active=[0,1]_.\r\nBut despite several attempts it is impossible to open a single index different from 0 without _toggle=True_.  \r\n\r\nHere's some code example ( from [https://panel.holoviz.org/reference/layouts/Accordion.html](url) ) :\r\n\r\n```\r\nimport panel as pn\r\npn.extension()\r\nfrom bokeh.plotting import figure\r\n\r\np1 = figure(width=300, height=300, name='Scatter', margin=5)\r\np1.scatter([0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 2, 1, 0])\r\n\r\np2 = figure(width=300, height=300, name='Line', margin=5)\r\np2.line([0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 2, 1, 0])\r\n\r\naccordion = pn.Accordion(('Scatter', p1), p2, active=[1])\r\naccordion\r\n```\r\n\r\n![image](https://user-images.githubusercontent.com/70373646/163144683-c04c29ac-3dc3-41d8-a352-891b6b3ce128.png)\r\n\r\n\r\nExemple with _toggle=True_ : \r\n\r\n![image](https://user-images.githubusercontent.com/70373646/163144585-1e5412d4-c96f-490a-9056-abdbab6df40c.png)\r\n\r\n\r\n\r\n\n", "before_files": [{"content": "import param\n\nfrom bokeh.models import Column as BkColumn, CustomJS\n\nfrom .base import NamedListPanel\nfrom .card import Card\n\n\nclass Accordion(NamedListPanel):\n    \n    active_header_background = param.String(default='#ccc', doc=\"\"\"\n        Color for currently active headers.\"\"\")\n\n    active = param.List(default=[], doc=\"\"\"\n        List of indexes of active cards.\"\"\")\n\n    header_color = param.String(doc=\"\"\"\n        A valid CSS color to apply to the expand button.\"\"\")\n\n    header_background = param.String(doc=\"\"\"\n        A valid CSS color for the header background.\"\"\")\n\n    toggle = param.Boolean(default=False, doc=\"\"\"\n        Whether to toggle between active cards or allow multiple cards\"\"\")\n\n    _bokeh_model = BkColumn\n    \n    _rename = {'active': None, 'active_header_background': None,\n               'header_background': None, 'objects': 'children',\n               'dynamic': None, 'toggle': None, 'header_color': None}\n\n    _toggle = \"\"\"\n    for (var child of accordion.children) {\n      if ((child.id !== cb_obj.id) && (child.collapsed == cb_obj.collapsed) && !cb_obj.collapsed) {\n        child.collapsed = !cb_obj.collapsed\n      }\n    }\n    \"\"\"\n\n    _synced_properties = [\n        'active_header_background', 'header_background', 'width',\n        'sizing_mode', 'width_policy', 'height_policy', 'header_color'\n    ]\n\n    def __init__(self, *objects, **params):\n        super().__init__(*objects, **params)\n        self._updating_active = False\n        self.param.watch(self._update_active, ['active'])\n        self.param.watch(self._update_cards, self._synced_properties)\n\n    def _get_objects(self, model, old_objects, doc, root, comm=None):\n        \"\"\"\n        Returns new child models for the layout while reusing unchanged\n        models and cleaning up any dropped objects.\n        \"\"\"\n        from panel.pane.base import RerenderError, panel\n        new_models = []\n        if len(self._names) != len(self):\n            raise ValueError('Accordion names do not match objects, ensure '\n                             'that the Tabs.objects are not modified '\n                             'directly. Found %d names, expected %d.' %\n                             (len(self._names), len(self)))\n        for i, (name, pane) in enumerate(zip(self._names, self)):\n            pane = panel(pane, name=name)\n            self.objects[i] = pane\n\n        for obj in old_objects:\n            if obj not in self.objects:\n                self._panels[id(obj)]._cleanup(root)\n\n        params = {k: v for k, v in self.param.values().items()\n                  if k in self._synced_properties}\n\n        ref = root.ref['id']\n        current_objects = list(self)\n        for i, (name, pane) in enumerate(zip(self._names, self)):\n            params.update(self._apply_style(i))\n            if id(pane) in self._panels:\n                card = self._panels[id(pane)]\n            else:\n                card = Card(\n                    pane, title=name, css_classes=['accordion'],\n                    header_css_classes=['accordion-header'],\n                    margin=self.margin\n                )\n                card.param.watch(self._set_active, ['collapsed'])\n                self._panels[id(pane)] = card\n            card.param.update(**params)\n            if ref in card._models:\n                panel = card._models[ref][0]\n            else:\n                try:\n                    panel = card._get_model(doc, root, model, comm)\n                    if self.toggle:\n                        cb = CustomJS(args={'accordion': model}, code=self._toggle)\n                        panel.js_on_change('collapsed', cb)\n                except RerenderError:\n                    return self._get_objects(model, current_objects[:i], doc, root, comm)\n            new_models.append(panel)\n        self._update_cards()\n        self._update_active()\n        return new_models\n\n    def _cleanup(self, root):\n        for panel in self._panels.values():\n            panel._cleanup(root)\n        super()._cleanup(root)\n\n    def _apply_style(self, i):\n        if i == 0:\n            margin = (5, 5, 0, 5)\n        elif i == (len(self)-1):\n            margin = (0, 5, 5, 5)\n        else:\n            margin = (0, 5, 0, 5)\n        return dict(margin=margin, collapsed = i not in self.active)\n\n    def _set_active(self, *events):\n        if self._updating_active:\n            return\n        self._updating_active = True\n        try:\n            if self.toggle and not events[0].new:\n                active = [list(self._panels.values()).index(events[0].obj)]\n            else:\n                active = []\n                for i, pane in enumerate(self.objects):\n                    if id(pane) not in self._panels:\n                        continue\n                    elif not self._panels[id(pane)].collapsed:\n                        active.append(i)\n            \n            if not self.toggle or active:\n                self.active = active\n        finally:\n            self._updating_active = False\n\n    def _update_active(self, *events):\n        if self._updating_active:\n            return\n        self._updating_active = True\n        try:\n            for i, pane in enumerate(self.objects):\n                if id(pane) not in self._panels:\n                    continue\n                self._panels[id(pane)].collapsed = i not in self.active\n        finally:\n            self._updating_active = False\n\n    def _update_cards(self, *events):\n        params = {k: v for k, v in self.param.values().items()\n                  if k in self._synced_properties}\n        for panel in self._panels.values():\n            panel.param.update(**params)\n", "path": "panel/layout/accordion.py"}], "after_files": [{"content": "import param\n\nfrom bokeh.models import Column as BkColumn, CustomJS\n\nfrom .base import NamedListPanel\nfrom .card import Card\n\n\nclass Accordion(NamedListPanel):\n    \n    active_header_background = param.String(default='#ccc', doc=\"\"\"\n        Color for currently active headers.\"\"\")\n\n    active = param.List(default=[], doc=\"\"\"\n        List of indexes of active cards.\"\"\")\n\n    header_color = param.String(doc=\"\"\"\n        A valid CSS color to apply to the expand button.\"\"\")\n\n    header_background = param.String(doc=\"\"\"\n        A valid CSS color for the header background.\"\"\")\n\n    toggle = param.Boolean(default=False, doc=\"\"\"\n        Whether to toggle between active cards or allow multiple cards\"\"\")\n\n    _bokeh_model = BkColumn\n    \n    _rename = {'active': None, 'active_header_background': None,\n               'header_background': None, 'objects': 'children',\n               'dynamic': None, 'toggle': None, 'header_color': None}\n\n    _toggle = \"\"\"\n    for (var child of accordion.children) {\n      if ((child.id !== cb_obj.id) && (child.collapsed == cb_obj.collapsed) && !cb_obj.collapsed) {\n        child.collapsed = !cb_obj.collapsed\n      }\n    }\n    \"\"\"\n\n    _synced_properties = [\n        'active_header_background', 'header_background', 'width',\n        'sizing_mode', 'width_policy', 'height_policy', 'header_color'\n    ]\n\n    def __init__(self, *objects, **params):\n        super().__init__(*objects, **params)\n        self._updating_active = False\n        self.param.watch(self._update_active, ['active'])\n        self.param.watch(self._update_cards, self._synced_properties)\n\n    def _get_objects(self, model, old_objects, doc, root, comm=None):\n        \"\"\"\n        Returns new child models for the layout while reusing unchanged\n        models and cleaning up any dropped objects.\n        \"\"\"\n        from panel.pane.base import RerenderError, panel\n        new_models = []\n        if len(self._names) != len(self):\n            raise ValueError('Accordion names do not match objects, ensure '\n                             'that the Tabs.objects are not modified '\n                             'directly. Found %d names, expected %d.' %\n                             (len(self._names), len(self)))\n        for i, (name, pane) in enumerate(zip(self._names, self)):\n            pane = panel(pane, name=name)\n            self.objects[i] = pane\n\n        for obj in old_objects:\n            if obj not in self.objects:\n                self._panels[id(obj)]._cleanup(root)\n\n        params = {k: v for k, v in self.param.values().items()\n                  if k in self._synced_properties}\n\n        ref = root.ref['id']\n        current_objects = list(self)\n        self._updating_active = True\n        for i, (name, pane) in enumerate(zip(self._names, self)):\n            params.update(self._apply_style(i))\n            if id(pane) in self._panels:\n                card = self._panels[id(pane)]\n            else:\n                card = Card(\n                    pane, title=name, css_classes=['accordion'],\n                    header_css_classes=['accordion-header'],\n                    margin=self.margin\n                )\n                card.param.watch(self._set_active, ['collapsed'])\n                self._panels[id(pane)] = card\n            card.param.update(**params)\n            if ref in card._models:\n                panel = card._models[ref][0]\n            else:\n                try:\n                    panel = card._get_model(doc, root, model, comm)\n                    if self.toggle:\n                        cb = CustomJS(args={'accordion': model}, code=self._toggle)\n                        panel.js_on_change('collapsed', cb)\n                except RerenderError:\n                    return self._get_objects(model, current_objects[:i], doc, root, comm)\n            new_models.append(panel)\n\n        self._updating_active = False\n        self._set_active()\n        self._update_cards()\n        self._update_active()\n        return new_models\n\n    def _cleanup(self, root):\n        for panel in self._panels.values():\n            panel._cleanup(root)\n        super()._cleanup(root)\n\n    def _apply_style(self, i):\n        if i == 0:\n            margin = (5, 5, 0, 5)\n        elif i == (len(self)-1):\n            margin = (0, 5, 5, 5)\n        else:\n            margin = (0, 5, 0, 5)\n        return dict(margin=margin, collapsed = i not in self.active)\n\n    def _set_active(self, *events):\n        if self._updating_active:\n            return\n        self._updating_active = True\n        try:\n            if self.toggle and events and not events[0].new:\n                active = [list(self._panels.values()).index(events[0].obj)]\n            else:\n                active = []\n                for i, pane in enumerate(self.objects):\n                    if id(pane) not in self._panels:\n                        continue\n                    elif not self._panels[id(pane)].collapsed:\n                        active.append(i)\n            \n            if not self.toggle or active:\n                self.active = active\n        finally:\n            self._updating_active = False\n\n    def _update_active(self, *events):\n        if self._updating_active:\n            return\n        self._updating_active = True\n        try:\n            for i, pane in enumerate(self.objects):\n                if id(pane) not in self._panels:\n                    continue\n                self._panels[id(pane)].collapsed = i not in self.active\n        finally:\n            self._updating_active = False\n\n    def _update_cards(self, *events):\n        params = {k: v for k, v in self.param.values().items()\n                  if k in self._synced_properties}\n        for panel in self._panels.values():\n            panel.param.update(**params)\n", "path": "panel/layout/accordion.py"}]}