Select a default value

Summary

Hello,
I am trying to use the st.radio function. I want to have a None Value for the return, as long as the user hasn’t choosen his answer.
Though, it’s not working for now, and i get the following API error:

**StreamlitAPIException**: Selectbox Value has invalid type: NoneType
Traceback:
File "C:\Users\hdandria\Documents\Gitlab\maintenance-predictive-explicabilite\Anomaly detection with Isolation Forest.py", line 147, in <module>
    option = st.selectbox(
             ^^^^^^^^^^^^^

Steps to reproduce

The code that I’m using is the one of the documentation:

import streamlit as st

genre = st.radio(
    "What's your favorite movie genre",
    [":rainbow[Comedy]", "***Drama***", "Documentary :movie_camera:"],
    index=None,
)

st.write("You selected:", genre)

Note: The st.radio functions behaves properly, as long as I don’t set index as None.
Do you have any idea on the origin of this problem ?

1 Like

Hey @Henri_d_ANDRIA,

Thanks for sharing this question!

I’m having trouble reproducing this error. What version of Streamlit are you running?

This is what I see when I run your code:

1 Like

The error is caused by some other code that you didn’t post.

Thank you for you answers.
I was running streamlit 1.26 when encoutering this error. I updated my version to 1.27, and the error disappeared.

2 Likes

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