Skip to content

Commit

Permalink
Better solution but I didn't test it and it's a bit more complex
Browse files Browse the repository at this point in the history
  • Loading branch information
antonymilne committed Apr 4, 2024
1 parent b9101c8 commit 6d0c73c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions vizro-core/examples/demo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"),
]
Expand Down

0 comments on commit 6d0c73c

Please sign in to comment.