444B / streamlit-analytics2

👀 Track & visualize user interactions with your streamlit app
MIT License
14 stars 2 forks source link

KeyError when using select_slider #25

Open 444B opened 4 months ago

444B commented 4 months ago

Original issue by upasana-mittal on 2023-02-02 22:13:34+00:00

I am getting a key error at st.select slider

start_rating, end_rating = st.select_slider("Select range of CSAT", options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], value=(2, 4))

KeyError: (2, 4)

444B commented 4 months ago

@upasana-mittal is this still relevant?

cakechaser commented 1 month ago

I'm also getting this issue with st.radio: KeyError: 'LTM'

File ".../streamlit/runtime/scriptrunner/script_runner.py", line 600, in _run_script
    exec(code, module.__dict__)
line 33, in <module>
    selector_screen = st.sidebar.radio(
File ".../streamlit_analytics2/main.py", line 180, in new_func
    counts["widgets"][label][selected] += 1

Selector code:

selector_screen = st.sidebar.radio(
    'Screen:',
    get_all_screens(st.session_state['screen_sorting']),
    key='screen_selector'
)

If I use a hardcoded list for options ['a', 'b'], I don't get this issue.

444B commented 1 month ago

@cakechaser thanks for validating the bug! I'll take a look into this and see if I can fix it

cakechaser commented 1 month ago

@444B thanks for the quick reply! I actually just fixed it on my side.

The get_all_screens function for the radio options was returning a pandas dataframe. I changed it to return a single column from the dataframe, and now the issue has disappeared.

Basically changing return df to return df['Column Name']

However streamlit itself is rendering the selector without issues regardless of this change.