File upload

Iā€™m trying to create an uploader file that works as input for all my tabs.
please help me how to do it.

sample code:
selected = option_menu(None, [ā€œHomeā€, ā€œUploadā€, ā€œTasksā€, ā€˜Settingsā€™],
icons=[ā€˜houseā€™, ā€˜cloud-uploadā€™, ā€œlist-taskā€, ā€˜gearā€™],
menu_icon=ā€œcastā€, default_index=0, orientation=ā€œhorizontalā€)
selected

if selected == ā€œHomeā€:
st.title(f"You have selected {selected}ā€œ)
if selected == ā€œUploadā€:
st.title(f"You have selected {selected}ā€)
with st.header(ā€˜1. Upload your CSV dataā€™):
uploaded_file = st.file_uploader(ā€œUpload your input fileā€, type=[ā€˜csvā€™])
if selected == ā€œTasksā€:
#st.title(f"You have selected {selected}")
### Read csv
iris = pd.read_table(uploaded_file , sep=ā€˜,ā€™, header=0)

Try this:

  1. Assign an explicit key to the file uploader.
    st.file_uploader("Upload your input file", type=["csv"], key="uploaded_file")

  2. Use session_state["uploaded_file"] to access the uploaded file where you need it.
    iris = pd.read_table(st.session_state["uploaded_file"] , sep=",", header=0)

I never tried this with a file uploader but it works with other widgets.

wonderful Goyo this worked thanks

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