Repository: holoviz/panel

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)






Discussion:

Resolving patch:
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 @@ def _get_objects(self, model, old_objects, doc, root, comm=None):
 
         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 @@ def _get_objects(self, model, old_objects, doc, root, comm=None):
                 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 @@ def _set_active(self, *events):
             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 = []


Test patch:
diff --git a/panel/tests/layout/test_accordion.py b/panel/tests/layout/test_accordion.py
--- a/panel/tests/layout/test_accordion.py
+++ b/panel/tests/layout/test_accordion.py
@@ -168,3 +168,11 @@ def test_accordion_set_card_collapsed_toggle(document, comm, accordion):
     assert accordion.active == [1]
 
     assert len(events) == 2
+
+
+def test_accordion_active_on_init(document, comm):
+    combinations = [[0], [1], [0, 1]]
+    for combination in combinations:
+        accordion = Accordion("1", "2", active=combination)
+        accordion.get_root(document, comm=comm)
+        assert accordion.active == combination