Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mui.Select callback event doesn't send information #26

Open
cardosofede opened this issue Jul 27, 2023 · 1 comment
Open

mui.Select callback event doesn't send information #26

cardosofede opened this issue Jul 27, 2023 · 1 comment

Comments

@cardosofede
Copy link

Hi, I just started with this library today and it's amazing!

This is the code that I'm using in a custom card to start strategies in Hummingbot:

with mui.Select(label="Scripts", onChange=lazy(lambda x: self.set_strategy(x, bot_name))):
  for script in scripts:
      mui.MenuItem(script, value=script)

and this is the method set_strategy:

@staticmethod
    def set_strategy(event, bot_name):
        st.session_state.active_bots[bot_name]["selected_strategy"] = event.target.value

When I press another button that triggers the execution I'm receiving this error:

  File "/Users/dardonacci/Documents/work/dashboard/ui_components/bot_performance_card.py", line 66, in <lambda>
    with mui.Select(label="Scripts", onChange=lazy(lambda x: self.set_strategy(x, bot_name))):
  File "/Users/dardonacci/Documents/work/dashboard/ui_components/bot_performance_card.py", line 15, in set_strategy
    st.session_state.active_bots[bot_name]["selected_strategy"] = event.target.value
  File "/Users/dardonacci/anaconda3/envs/dashboard/lib/python3.9/site-packages/streamlit_elements/core/callback.py", line 138, in __getattr__
    return self.__getitem__(value)

I also inspected the event that arrives in the function and is the dict --> {"isTrusted":false}

I don't know react so probably I'm missing something in how to use mui.Select, any help is welcome!

@chrda81
Copy link

chrda81 commented Aug 8, 2023

I had the same problem and found the answer mentioned here #2

I have a TextField with the select=True option and can access the value by using onChange=sync(None, 'select_value'). The value from the 'select_value' returning dict can then be accessed by .props.value

if st.session_state.select_value is not None:
    # Select must use the second sync var
    select_value = st.session_state.select_value.props.value

I hope this helps for the mui.Select too, or you switch to the TextField with select option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants