S
Solara3mo ago
juan

CSV file as input?

Is there a way to input using FileDrop (or any other way) a CSV file and use it?
4 Replies
ntjess
ntjess2mo ago
Does this example work for you? https://solara.dev/documentation/components/input/file_drop#arguments_1 Link to source code: https://github.com/widgetti/solara/blob/master/solara/website/pages/documentation/components/input/file_drop.py It should show how to upload a csv and run a function on the contents
GitHub
solara/solara/website/pages/documentation/components/input/file_dro...
A Pure Python, React-style Framework for Scaling Your Jupyter and Web Apps - widgetti/solara
MaartenBreddels
MaartenBreddels2mo ago
It works for me, does it still not work for you?
robert.marik
robert.marik2mo ago
Works for me. Is is necessary to load full file and use BytesIO
Helleeni
Helleeni5w ago
Hi, maybe related to this. I was struggling to read .csv to a Pandas dataframe by using file drop. Eventually could read the .csv like this (using file_obj and data from file drop with Lazy=False):
from io import StringIO
s=str(file['data'],'utf-16') # Convert bytes to string, my csv is utf-16 coded
df.value = pd.read_csv(StringIO(s), skiprows=0, sep='\t', encoding = 'utf-16', header=1) # again my .csv had an empty row, tab as a separator, and header on first row
from io import StringIO
s=str(file['data'],'utf-16') # Convert bytes to string, my csv is utf-16 coded
df.value = pd.read_csv(StringIO(s), skiprows=0, sep='\t', encoding = 'utf-16', header=1) # again my .csv had an empty row, tab as a separator, and header on first row
Apparently needed to make a string from the data and then read by using StringIO. Worked for me. In this example df is a reactive variable dataframe.
Want results from more Discord servers?
Add your server