[Python] Error in accessing widget value using Shiny in Python

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

  1. Stack

    Stack Membro Participativo

    I have recently been called upon to make some changes to an application built using Shiny for Python. I started with what I thought would be a very simple change, but am already running into issues.

    Previously there was hard-coded a limit:

    MAX_LOCATIONS_PER = 2 # Change this as needed


    This now needs to be adjustable by the user, so I added a slider to the UI.

    def sidebar_shelf():
    return ui.sidebar(
    shinyswatch.theme_picker_ui(),
    ui.card(
    ui.card_header(
    "Max Locations",
    style='color:#f8f9f9; background:#34495e !important;',
    align='center'),
    ui.input_slider("Max_Loc", "Select a value", min=1, max=25, value=2),
    fill=True),...


    And then in the server

    def server(input, output, session):
    shinyswatch.theme_picker_server()
    store_assign_data = reactive.value(pd.DataFrame())
    store_assignments = reactive.value()

    @reactive.Effect
    def _():
    MAX_LOCATIONS_PER = input.Max_Loc()


    But later when I attempt to use the MAX_LOCATIONS_PER variable

    if assigned_count[idx] < MAX_LOCATIONS_PER:


    The app throws

    NameError: name 'MAX_LOCATIONS_PER' is not defined


    Am I missing something?

    Continue reading...

Compartilhe esta Página