[Python] How to access code in different files inside the main app?

Discussão em 'Python' iniciado por Stack, Junho 16, 2025.

  1. Stack

    Stack Membro Participativo

    I have a rather large app.py file, so I'd like to take a nav panel out and store it in a separate file. I'm not sure how to access code from a different file and include it in the main app.

    The app.py file:

    import page

    from shiny import reactive, render, req, ui
    from shiny.express import input, ui

    with ui.navset_hidden(id="selected_navset_tab"):
    # Homepage
    with ui.nav_panel("Welcome", value="page_home"):
    with ui.card():
    # Variable calculated
    ui.input_selectize(
    "filler", "Filler",
    ["list", "of", "items", "here"],
    multiple=False
    )


    The other file, page.py:

    from shiny import reactive, render, req, ui
    from shiny.express import input, ui

    with ui.nav_panel("Page I want to put in the main app", value="other_page"):
    @render.express
    def filler_text():
    "Filler text"


    How can I import the other_page nav panel to show as part of the navset_tab in the main app.py file, without actually putting it in the code?

    Continue reading...

Compartilhe esta Página