ValueError when I use DataFrame data for st.radio button

I meet the following error: ValueError("{} is not in iterable".format(str(x))).

[My code]
import streamlit as st
import pandas as pd

dict_data = {‘A’: [‘dog’, ‘cat’, ‘bird’], ‘B’: [1, 2, 3],}
df = pd.DataFrame(dict_data)
st.radio(‘DataFrame data’, df)

[Error Result]

Exception in thread ScriptRunner.scriptThread:
Traceback (most recent call last):
File “C:\Anaconda3\lib\threading.py”, line 973, in _bootstrap_inner
self.run()
File “C:\Anaconda3\lib\threading.py”, line 910, in run
self._target(*self._args, **self._kwargs)
File “C:\Anaconda3\lib\site-packages\streamlit\scriptrunner\script_runner.py”, line 289, in _run_script_thread
widget_states = self._session_state.get_widget_states()
File “C:\Anaconda3\lib\site-packages\streamlit\state\safe_session_state.py”, line 82, in get_widget_states
return self.state.get_widget_states()
File “C:\Anaconda3\lib\site-packages\streamlit\state\session_state.py”, line 576, in get_widget_states
return self.new_widget_state.as_widget_states()
File “C:\Anaconda3\lib\site-packages\streamlit\state\session_state.py”, line 249, in as_widget_states
states = [
File “C:\Anaconda3\lib\site-packages\streamlit\state\session_state.py”, line 252, in
if self.get_serialized(widget_id)
File “C:\Anaconda3\lib\site-packages\streamlit\state\session_state.py”, line 230, in get_serialized
serialized = metadata.serializer(item.value)
File “C:\Anaconda3\lib\site-packages\streamlit\elements\radio.py”, line 166, in serialize_radio
return index
(options, v)
File “C:\Anaconda3\lib\site-packages\streamlit\util.py”, line 129, in index

raise ValueError("{} is not in iterable".format(str(x)))
ValueError: dog is not in iterable

Hi @choies1 :wave:

I suspect you’re using an older version of the Streamlit library. You can check what version you’re using by running the following in your terminal:

streamlit version

Your code snippet runs without issues on Streamlit 1.9.0:

I would suggest upgrading to the latest Streamlit version:

Happy Streamlit-ing! :balloon:
Snehan

I tested it on windows 11. My streamlit version is 1.9.0 and python version is 3.9.7.

I still have the same problem. What should I check?

I would start by including the following line before you define the dataframe:

st.write(st.__version__)

As a sanity check, that will display the version of the Streamlit your app is running on. I suspect you have multiple conda environments with different versions of Streamlit. The environment with which you run streamlit run might not be the same one when you check your Streamlit version.

I recommend going through our installation instructions for Windows to set up a clean environment.

Hi @choies1 :wave:

Please disregard my reply about Streamlit versions. I now understand your issue: while you’re able to select the options via radio buttons, the ValueError: dog is not in iterable appears in your terminal. This occurs even though the frontend does not raise any errors!

I believe you’ve discovered a bug :bug:. You can report the bug by creating a new issue in our GitHub repo and our engineers will work on a fix. Thank you for brining this to our attention! I’ve filed an internal bug report.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.