[Python] Leafmap refresh with each interaction in streamlit

Discussão em 'Python' iniciado por Stack, Abril 26, 2025.

  1. Stack

    Stack Membro Participativo

    Why when I interact with my Streamlit interface, the Leafmap gets updated? Practically every click I give causes it to update or refresh. How can I avoid this? Attached is a test video of what is happening. This is annoying. Thanks in advance for your answer.

    import streamlit as st
    import leafmap.foliumap as leafmap


    st.set_page_config(
    page_title=None,
    page_icon=None,
    layout="wide",
    initial_sidebar_state="auto",
    )

    st.html(
    """
    <style>
    header {visibility: hidden;}
    footer {visibility: hidden;}
    .block-container {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    }
    .main {
    padding: 0 !important;
    margin: 0 !important;
    }
    .css-1aumxhk {
    margin-top: 0 !important;
    }

    iframe {
    height: 100vh;
    display: block;
    }
    </style>
    """
    )

    m = leafmap.Map(center=[-0.1807, -78.4678], zoom=7)
    m.to_streamlit()

    for i, variable in enumerate(st.session_state.variables_seleccionadas):
    col1, col2 = st.sidebar.columns([4, 1])
    with col1:
    st.subheader(f"{alias_variables[variable]}")
    with col2:
    if st.button("️", key=f"eliminar_{variable}", help="Eliminar esta variable"):
    st.session_state.variables_seleccionadas.remove(variable)
    st.session_state.selecciones.pop(variable, None)
    st.rerun()

    modelos = []
    for modelo in variables_modelos[variable]:
    help_message = descripciones_modelos.get(modelo)
    if st.sidebar.checkbox(
    alias_modelos[modelo],
    key=f"{variable}_{modelo}",
    help=help_message
    ):
    modelos.append(modelo)

    st.session_state.selecciones[variable] = modelos
    st.sidebar.markdown("<div style='margin-bottom: 1px;margin-top: 0px;'></div>", unsafe_allow_html=True)


    Video test

    Continue reading...

Compartilhe esta Página