File_uploader() - ValueError: I/O operation on closed file.
See original GitHub issueSummary
I upgraded Streamlit and file_uploader() haven’t the expected behavior. I’m trying to load a file, then use a dropdown menu to select the right column to analyse. I adapted the proposed solution here , but I still have “ValueError: I/O operation on closed file.” when I select a value in the dropdown menu.
Steps to reproduce
What are the steps we should take to reproduce the bug:
- Select a file to upload
- Select a value in the dropdown menu
Expected behavior:
Explain what you expect to happen when you go through the steps above, assuming there were no bugs.
Is this a regression?
That is, did this use to work the way you expected in the past? yes
Debug info
streamlit==0.70.0 streamlit-nightly==0.70.1.dev20201101
Additional information
Here is my code :
def upload_file():
file = st.sidebar.file_uploader("Choisir un fichier", type=["csv"])
if file is None:
return None,None,None,None,None,None
file.seek(0)
df = pd.read_csv(file, sep=';',index_col=None, encoding = "utf-8")
menu_value = st.sidebar.selectbox('Quelle colonne correspond au texte à analyser ?',df.columns)
language,remove_hashtags,remove_usernames,ncomponents=sidebar()
return(df,menu_value,language,remove_hashtags,remove_usernames,ncomponents)
def sidebar():
language = st.sidebar.selectbox('Quelle est la langue du corpus ?',['french','english'])
remove_hashtags=st.sidebar.checkbox('Supprimer les hashtags',value=False)
remove_usernames=st.sidebar.checkbox('Supprimer les mentions',value=False)
ncomponents=st.sidebar.slider("Combien de topics à détecter", min_value=0, max_value=100, value=20, step=1, format=None, key=None)
return language,remove_hashtags,remove_usernames,ncomponents
def main():
st.set_page_config(
page_title="Topic Modeling",
page_icon="🧊",
layout="wide",
initial_sidebar_state="expanded",
)
st.set_option('deprecation.showfileUploaderEncoding', False)
st.sidebar.title('Paramètres')
st.title('Topic Modelling')
projet=st.sidebar.text_input("Donner un nom de projet", value='monProjet', max_chars=None, key=None, type='default')
df,menu_value,language,remove_hashtags,remove_usernames,ncomponents=upload_file()
if st.sidebar.button('Valider'):
analyse(projet,language,remove_hashtags,remove_usernames,ncomponents,df_input,menu_value)
list_results(path="./"+projet+"/")
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
ValueError : I/O operation on closed file - Stack Overflow
When I try to write to the file it reports the error: ValueError: I/O operation on closed file. python · csv · file-io...
Read more >ValueError: I/O operation on closed file in Python | bobbyhadz
The Python ValueError: I/O operation on closed file occurs when we try to perform an operation on a closed file. To solve the...
Read more >V0.71.0 - file_uploader : I/O operation on closed file - Streamlit
I've been getting this error from file_uploader when I adjust a slider or do anything that reruns the app. I saw posts talking...
Read more >ValueError: I/O operations on closed file - STechies
ValueError : I/O operations on closed file. · Example: # Creating a file 'MyFile' f = open("MyFile",'w') # Entering data after opening the...
Read more >It says "ValueError: I/O operation on closed file" but i opened it
import sys print('some text') a='moretext.1'.split('.') output = open('output.txt', 'w') print(a, file=output) output.close() ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for sending this along. The fix was recently merged and will be available in version 0.73 that will be coming out this week. If you would like to get the latest, you can use our
streamlit-nightly
package that is updated with the latest changes every day.I think this is the best thread to leave this – I am encountering this error when using the
file_uploader
in combination withst.radio()
, anduploaded_file.seek(0)
does not solve the problem. Ill admit, I honestly do not understand whatseek(0)
is fundamentally doing, so maybe I am missing something obvious. Here is a minimal reproducible example:streamlit 0.71.0 and 0.72.0
When users upload a file, switch to manually entering text, and then try to upload again, the
ValueError: I/O operation on closed file
is thrown. This is a regression, as I did not encounter this error with a much older version of streamlitany help would be much appreciated!