Streamlit ANTD Menu Highlight Issue: Ensuring Accurate Page Selection

Hey! I’m working on a menu using Streamlit ANTD components. I need to implement a button that can switch between menu pages. Currently, when I’m on Page1 and press the button, I get redirected to Page3 successfully. However, the highlight on the menu page doesn’t update correctly. Despite changing the content to Page3, the menu still indicates that Page1 is selected. How can I resolve this issue?

Streamlit ANTD Menu

import streamlit as st
import streamlit_antd_components as sac

if "manual" not in st.session_state:
    st.session_state.manual = 0

def onClick():
    setattr(st.session_state, "manual", 2)
    setattr(st.session_state, "key", "Page3")

ind = sac.menu(
    ["Page1", "Page2", "Page3"],
    format_func='title',
    index=st.session_state.manual,
    key="key",
)

st.write("KEY: ", st.session_state.key)
st.write("INDEX: ", st.session_state.manual)

st.button("Submit", on_click=onClick)

if st.session_state.key == "Page1":
    st.title("PAGE 1")
elif st.session_state.key == "Page2":
    st.title("PAGE 2")
elif st.session_state.key == "Page3":
    st.title("PAGE 3")
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.