(
pages: Sequence[PageType] | Mapping[SectionHeader, Sequence[PageType]],
*,
position: Literal["sidebar", "hidden", "top"],
expanded: bool | int,
)
| 330 | |
| 331 | |
| 332 | def _navigation( |
| 333 | pages: Sequence[PageType] | Mapping[SectionHeader, Sequence[PageType]], |
| 334 | *, |
| 335 | position: Literal["sidebar", "hidden", "top"], |
| 336 | expanded: bool | int, |
| 337 | ) -> StreamlitPage: |
| 338 | if isinstance(pages, Sequence): |
| 339 | converted_pages = [convert_to_streamlit_page(p) for p in pages] |
| 340 | nav_sections = {"": converted_pages} |
| 341 | else: |
| 342 | nav_sections = { |
| 343 | section: [convert_to_streamlit_page(p) for p in section_pages] |
| 344 | for section, section_pages in pages.items() |
| 345 | } |
| 346 | page_list = pages_from_nav_sections(nav_sections) |
| 347 | |
| 348 | if not page_list: |
| 349 | raise StreamlitAPIException( |
| 350 | "`st.navigation` must be called with at least one `st.Page`." |
| 351 | ) |
| 352 | |
| 353 | default_page = None |
| 354 | pagehash_to_pageinfo: dict[PageHash, PageInfo] = {} |
| 355 | |
| 356 | # Get the default page. |
| 357 | for section_header in nav_sections: |
| 358 | for page in nav_sections[section_header]: |
| 359 | if page._default: |
| 360 | if default_page is not None: |
| 361 | raise StreamlitAPIException( |
| 362 | "Multiple Pages specified with `default=True`. " |
| 363 | "At most one Page can be set to default." |
| 364 | ) |
| 365 | default_page = page |
| 366 | |
| 367 | if default_page is None: |
| 368 | non_external_pages = [p for p in page_list if not p.is_external] |
| 369 | if not non_external_pages: |
| 370 | raise StreamlitAPIException( |
| 371 | "At least one non-external page is required. " |
| 372 | "External URL pages cannot be the default page." |
| 373 | ) |
| 374 | default_page = non_external_pages[0] |
| 375 | default_page._default = True |
| 376 | |
| 377 | ctx = get_script_run_ctx() |
| 378 | if not ctx: |
| 379 | # This should never run in Streamlit, but we want to make sure that |
| 380 | # the function always returns a page |
| 381 | default_page._can_be_called = True |
| 382 | return default_page |
| 383 | |
| 384 | # Build the pagehash-to-pageinfo mapping. |
| 385 | for section_header in nav_sections: |
| 386 | for page in nav_sections[section_header]: |
| 387 | script_path = str(page._page) if isinstance(page._page, Path) else "" |
| 388 | |
| 389 | script_hash = page._script_hash |
no test coverage detected
searching dependent graphs…