HI, i am wondering is there a way by which we can add a validation like functionality in our streamlit app.
basically, i am working on streamlit project, where i wanted to perform the EDA and model building task on the dataset that is being provided by the user. for this purpose, i am adding 2 different radio button. (Explore and Model) now what i wanted is till the time the user won’t upload the data, radio button should be disabled (disabled = True), and as soon as user uploads it. setting of radio button should change to (disabled = False). Please let me know if there is a way by which i can perform this task.
Hey @abhi_or_22, welcome to our forum
In order to change the disabled
property of st.radio()
depending on whether the user uploaded the data, I would recommend you to make a variable which is True
or False
based on whether st.file_uploader
is None
or not and use it for the disabled=
property.
You can play with the following code in this app, hope that helps:
import streamlit as st
import pandas as pd
# Initialize the boolean telling you if the user uploaded anything...
has_uploaded_file = False
uploaded_file = st.file_uploader("Upload any file below")
if uploaded_file is not None:
# Ah! User has uploaded some data. Now changing to "True"
has_uploaded_file = True
task = st.radio(
"Choose task",
["Explore", "Model"],
disabled=not has_uploaded_file, # <-- See here!
)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.