L i;>vUddlmZddlmZmZmZddlmZddlm Z m Z m Z ddl m Z ddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZmZdd lmZe rddl m!Z!m"Z"e#Z$de%d<e#ezegdfzezZ&de%d< ddZ' ddZ(ddZ)edddd ddZ* ddZ+y) ) annotations)CallableMappingSequence)Path) TYPE_CHECKINGLiteral TypeAlias)config)StreamlitAPIException) StreamlitPage) ForwardMsg) Navigation)gather_metrics) PagesManager)ScriptRunContextget_script_run_ctx)is_emoji)PageHashPageInfor SectionHeaderNPageTypect|tr|St|tr t|St|tr t|St |r t|St dt |d)z5Convert various input types to StreamlitPage objects.zInvalid page type: zY. Must be either a string path, a pathlib.Path, a callable function, or a st.Page object.) isinstancer strrcallabler type) page_inputs c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/commands/navigation.pyconvert_to_streamlit_pager )sw*m,*c"Z((*d#Z(( Z((  d:./0D D crg}|jD]!}|j|j#|S)N)valuesextendcopy) nav_sections page_listpagess rpages_from_nav_sectionsr)@s=I$$&'&' r!c\t}d|j_|j|y)N)rpage_not_found page_nameenqueue)ctxmsgs rsend_page_not_foundr1Js# ,C#%C KKr! navigationsidebarFpositionexpandedczt|tr|dvrtd|ddt_t |||S)u Configure the available pages in a multipage app. Call ``st.navigation`` in your entrypoint file to define the available pages for your app. ``st.navigation`` returns the current page, which can be executed using ``.run()`` method. When using ``st.navigation``, your entrypoint file (the file passed to ``streamlit run``) acts like a router or frame of common elements around each of your pages. Streamlit executes the entrypoint file with every app rerun. To execute the current page, you must call the ``.run()`` method on the ``StreamlitPage`` object returned by ``st.navigation``. The set of available pages can be updated with each rerun for dynamic navigation. By default, ``st.navigation`` displays the available pages in the sidebar if there is more than one page. This behavior can be changed using the ``position`` keyword argument. As soon as any session of your app executes the ``st.navigation`` command, your app will ignore the ``pages/`` directory (across all sessions). Parameters ---------- pages : Sequence[page-like], Mapping[str, Sequence[page-like]] The available pages for the app. To create a navigation menu with no sections or page groupings, ``pages`` must be a list of page-like objects. Page-like objects are anything that can be passed to ``st.Page`` or a ``StreamlitPage`` object returned by ``st.Page``. To create labeled sections or page groupings within the navigation menu, ``pages`` must be a dictionary. Each key is the label of a section and each value is the list of page-like objects for that section. If you use ``position="top"``, each grouping will be a collapsible item in the navigation menu. For top navigation, if you use an empty string as a section header, the pages in that section will be displayed at the beginning of the menu before the collapsible sections. When you use a string or path as a page-like object, they are internally passed to ``st.Page`` and converted to ``StreamlitPage`` objects. In this case, the page will have the default title, icon, and path inferred from its path or filename. To customize these attributes for your page, initialize your page with ``st.Page``. position : "sidebar", "top", or "hidden" The position of the navigation menu. If this is ``"sidebar"`` (default), the navigation widget appears at the top of the sidebar. If this is ``"top"``, the navigation appears in the top header of the app. If this is ``"hidden"``, the navigation widget is not displayed. If there is only one page in ``pages``, the navigation will be hidden for any value of ``position``. expanded : bool Whether the navigation menu should be expanded. If this is ``False`` (default), the navigation menu will be collapsed and will include a button to view more options when there are too many pages to display. If this is ``True``, the navigation menu will always be expanded; no button to collapse the menu will be displayed. If ``st.navigation`` changes from ``expanded=True`` to ``expanded=False`` on a rerun, the menu will stay expanded and a collapse button will be displayed. The parameter is only used when ``position="sidebar"``. Returns ------- StreamlitPage The current page selected by the user. To run the page, you must use the ``.run()`` method on it. Examples -------- The following examples show different possible entrypoint files, each named ``streamlit_app.py``. An entrypoint file is passed to ``streamlit run``. It manages your app's navigation and serves as a router between pages. **Example 1: Use a callable or Python file as a page** You can declare pages from callables or file paths. If you pass callables or paths to ``st.navigation`` as a page-like objects, they are internally converted to ``StreamlitPage`` objects using ``st.Page``. In this case, the page titles, icons, and paths are inferred from the file or callable names. ``page_1.py`` (in the same directory as your entrypoint file): >>> import streamlit as st >>> >>> st.title("Page 1") ``streamlit_app.py``: >>> import streamlit as st >>> >>> def page_2(): ... st.title("Page 2") >>> >>> pg = st.navigation(["page_1.py", page_2]) >>> pg.run() .. output:: https://doc-navigation-example-1.streamlit.app/ height: 200px **Example 2: Group pages into sections and customize them with ``st.Page``** You can use a dictionary to create sections within your navigation menu. In the following example, each page is similar to Page 1 in Example 1, and all pages are in the same directory. However, you can use Python files from anywhere in your repository. ``st.Page`` is used to give each page a custom title. For more information, see |st.Page|_. Directory structure: >>> your_repository/ >>> ├── create_account.py >>> ├── learn.py >>> ├── manage_account.py >>> ├── streamlit_app.py >>> └── trial.py ``streamlit_app.py``: >>> import streamlit as st >>> >>> pages = { ... "Your account": [ ... st.Page("create_account.py", title="Create your account"), ... st.Page("manage_account.py", title="Manage your account"), ... ], ... "Resources": [ ... st.Page("learn.py", title="Learn about us"), ... st.Page("trial.py", title="Try it out"), ... ], ... } >>> >>> pg = st.navigation(pages) >>> pg.run() .. output:: https://doc-navigation-example-2.streamlit.app/ height: 300px **Example 3: Use top navigation** You can use the ``position`` parameter to place the navigation at the top of the app. This is useful for apps with a lot of pages because it allows you to create collapsible sections for each group of pages. The following example uses the same directory structure as Example 2 and shows how to create a top navigation menu. ``streamlit_app.py``: >>> import streamlit as st >>> >>> pages = { ... "Your account": [ ... st.Page("create_account.py", title="Create your account"), ... st.Page("manage_account.py", title="Manage your account"), ... ], ... "Resources": [ ... st.Page("learn.py", title="Learn about us"), ... st.Page("trial.py", title="Try it out"), ... ], ... } >>> >>> pg = st.navigation(pages, position="top") >>> pg.run() .. output:: https://doc-navigation-top.streamlit.app/ height: 300px **Example 4: Stateful widgets across multiple pages** Call widget functions in your entrypoint file when you want a widget to be stateful across pages. Assign keys to your common widgets and access their values through Session State within your pages. ``streamlit_app.py``: >>> import streamlit as st >>> >>> def page1(): >>> st.write(st.session_state.foo) >>> >>> def page2(): >>> st.write(st.session_state.bar) >>> >>> # Widgets shared by all the pages >>> st.sidebar.selectbox("Foo", ["A", "B", "C"], key="foo") >>> st.sidebar.checkbox("Bar", key="bar") >>> >>> pg = st.navigation([page1, page2]) >>> pg.run() .. output:: https://doc-navigation-multipage-widgets.streamlit.app/ height: 350px .. |st.Page| replace:: ``st.Page`` .. _st.Page: https://docs.streamlit.io/develop/api-reference/navigation/st.page )r3hiddentopzInvalid position "zG". The position parameter must be one of "sidebar", "hidden", or "top".Fr4)rrr ruses_pages_directory _navigation)r(r5r6s rr2r2PsPn h $8T(T#  +S S  ).L% ux( CCr!c >t|tr|Dcgc] }t|}}d|i}n<|jDcic]\}}||Dcgc] }t|c}!}}}}t |}|s t dd} i} |D](} || D]} | j s| t d| } *| |d} d| _t} | s d| _| S|D]} || D]} t| jtrt| jnd}| j}|| vrt d| jd|| j| j|| jd| |<t!}|d k(r*t"j$j&|j(_n|d k(r*t"j$j,|j(_no|d k(rjt/j0d d ur*t"j$j&|j(_n)t"j$j2|j(_||j(_|j7|j(j8dd|D]} || D]} |j(j:j=}| j|_| j|_ tC| jrd| jn | j|_| j |_"| |_#| j|_$| jJjM| | jJjO| j}d}|r7|d}|Dcgc]}|j|k(s|}}tQ|dkDr|d}|s tS| | }d|_|j|j(_| jU|j| jW||Scc}wcc}wcc}}}wcc}w)Nr+z;`st.navigation` must be called with at least one `st.Page`.zUMultiple Pages specified with `default=True`. At most one Page can be set to default.rTz+Multiple Pages specified with URL pathname zl. URL pathnames must be unique. The url pathname may be inferred from the filename, callable name, or title.)page_script_hashr-icon script_path url_pathnamer8r9r3zclient.showSidebarNavigationFzemoji:)fallback_page_hashr=),rrr itemsr)r _defaultr_can_be_called_pagerr _script_hashurl_pathtitler>rNavigationProtoPositionHIDDENr2r5TOPr get_optionSIDEBARr6keyssections app_pagesaddr=r-r is_defaultsection_headerr@ pages_manager set_pagesget_page_scriptlenr1set_mpa_v2_pager.)r(r5r6pconverted_pagesr&section section_pagesr' default_pagepagehash_to_pageinforTpager/r? script_hashr0 found_pagepage_to_returnfound_page_script_hashmatching_pagess rr;r;3s %"AFGA4Q7GGO, +0++-  & MJq/2J J  ( 5I # I  L57'$ 0 $D}}+/B $  $$ | $   C '+ #' 0 D-7 D-I#djj/rK++K22,A$--QKK%0!ZZ * $ 1  - , ,C8"1":":"A"A U "1":":">"> Y    ; < E&5&>&>&E&ECNN #&5&>&>&F&FCNN #&CNN!-!2!2!4CNNA&+ 0 +D((,,.A!%!2!2A **AK-5dii-@vdii[)diiAF==AL-A !]]AN ++ 45""22'443JN!+,>!?  ANN6L$LA   ~  "+A.N C %%)N!&4&A&ACNN#334KK gHK z s)P  PP!P<PPP)rrreturnr )r&z(dict[SectionHeader, list[StreamlitPage]]rfzlist[StreamlitPage])r/rrfNone)r(z?Sequence[PageType] | Mapping[SectionHeader, Sequence[PageType]]r5z#Literal['sidebar', 'hidden', 'top']r6boolrfr ), __future__rcollections.abcrrrpathlibrtypingrr r streamlitr streamlit.errorsr streamlit.navigation.pager streamlit.proto.ForwardMsg_pb2rstreamlit.proto.Navigation_pb2rrIstreamlit.runtime.metrics_utilrstreamlit.runtime.pages_managerr7streamlit.runtime.scriptrunner_utils.script_run_contextrrstreamlit.string_utilrstreamlit.source_utilrrrr__annotations__rr r)r1r2r;r!rrys#7744235H98+8 yDj8BH#55 E)E.:  5> _D J_D2_D _D  _D_DDz Jz2z z  zr!