nicedouble / StreamlitAntdComponents

A Streamlit component to display Antd-Design
https://nicedouble-streamlitantdcomponentsdemo-app-middmy.streamlit.app/
MIT License
440 stars 29 forks source link

on_change does not work #68

Open quying opened 2 months ago

quying commented 2 months ago

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

Socvest commented 2 months ago

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

maxronk commented 2 months ago

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

maggie1121 commented 1 month ago

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: ()