StreamlitAntdComponents
StreamlitAntdComponents copied to clipboard
on_change does not work
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 I have built a patch reflecting changes in v. 1.36.0 here.
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
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 in the meanwhile did you found any solution?