StreamlitAntdComponents icon indicating copy to clipboard operation
StreamlitAntdComponents copied to clipboard

on_change does not work

Open quying opened this issue 1 year ago • 4 comments

When I set on_change callback, it's not called.

def switch_session():
    st.write(f'session changed: {st.session_state.new_session}')

menu_items = [sid for sid in sorted_ids]
item = sac.menu(menu_items, open_all=True, format_func=format_session, on_change=switch_session, key="new_session")

Streamlit==1.36.0 streamlit_antd_components==0.3.2

quying avatar Sep 04 '24 21:09 quying

@quying I have built a patch reflecting changes in v. 1.36.0 here.

Socvest avatar Sep 10 '24 08:09 Socvest

I get an error as well - TypeError: ButtonsItem.init() got an unexpected keyword argument 'on_change'

    # Function to add a new tab
    def add_tab():
        st.session_state.num_tabs += 1

    # Function to remove a tab
    def remove_tab():
        if st.session_state.num_tabs > 1:
            st.session_state.num_tabs -= 1

    sac.buttons([
    sac.ButtonsItem(label="Add Tab", on_change=add_tab),
    sac.ButtonsItem(label="Remove Tab", on_change=remove_tab, disabled=st.session_state.num_tabs == 1),
    ],
    )

Name: streamlit Version: 1.38.0

Name: streamlit-antd-components Version: 0.3.2

maxronk avatar Sep 15 '24 17:09 maxronk

sac.buttons callback args is still broken.

    def callback(*args, **kwargs):
        print(f"callback args: {args}")

    def test():
        key = uri + f"_{name}_buttons"
        print(f"key: {key}")
        sac.buttons(
            [sac.ButtonsItem(uri) for uri in uris],
            index=None,
            size='xs',
            key=key,
            on_change=callback, args=(key,)
        )

The above code is broken with an upgrade if streamlit1.36.0, the callback args print out empty tuple: ()

maggie1121 avatar Oct 14 '24 22:10 maggie1121

@maggie1121 in the meanwhile did you found any solution?

luminoso avatar Apr 14 '25 14:04 luminoso