From 6d0c73c8d60c40582a2406078c21b1be0ef727d1 Mon Sep 17 00:00:00 2001 From: Antony Milne Date: Thu, 4 Apr 2024 17:38:41 +0100 Subject: [PATCH] Better solution but I didn't test it and it's a bit more complex --- vizro-core/examples/demo/app.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/vizro-core/examples/demo/app.py b/vizro-core/examples/demo/app.py index 0e60ef0d4..694cd699f 100644 --- a/vizro-core/examples/demo/app.py +++ b/vizro-core/examples/demo/app.py @@ -34,14 +34,11 @@ class CustomNavLink(vm.NavLink): """Custom NavLink that uses CollapsedAccordion.""" type: Literal["custom_nav_link"] = "custom_nav_link" + nav_selector: vm.Accordion = None def pre_build(self): - self._nav_selector = CollapsedAccordion(pages=self.pages) - - # This isn't doing anything - you can remove it - # def build(self, *, active_page_id=None): - # nav_link_build_obj = super().build() - # return nav_link_build_obj + self._nav_selector = self.nav_selector or vm.Accordion() + self._nav_selector.pages = self.nav_selector.pages or self.pages gapminder = px.data.gapminder() @@ -570,11 +567,13 @@ def create_home_page(): navigation=vm.Navigation( nav_selector=vm.NavBar( items=[ - CustomNavLink(label="Homepage", pages=["Homepage"], icon="Home"), + CustomNavLink(label="Homepage", pages=["Homepage"], icon="Home"), # Leave this with the default + # Accordion() (which won't appear because there's only one page) CustomNavLink( label="Analysis", pages=["Variable Analysis", "Relationship Analysis", "Benchmark Analysis"], icon="Stacked Bar Chart", + nav_selector=CollapsedAccordion(), # Set to CollapsedAccordion() to override Accordion() default ), CustomNavLink(label="Summary", pages=["Continent Summary"], icon="Globe"), ]