I would now expect to have access to df, for example to plot in a panel or perform operations on in Python. However, this code runs without error and also does not create a df variable.
Does not work for me. I added an if-statement at the beginning of get_data_from_file() to make sure I do not immediately run into an error.
import panel as pn
import pandas as pd
from io import BytesIO
pn.extension()
uploadFile = pn.widgets.FileInput(accept=".csv")
def get_data_from_file(file):
if file is not None:
df = pd.read_csv(BytesIO(file))
return df
df = pn.bind(get_data_from_file,uploadFile)
dataframe=df()
uploadFile
This code, however, create a dataframe of type NoneType. Without the if statement in the function I immediately get the error EmptyDataError: No columns to parse from file
OK, so I got it working. It seems that the line dataframe=df() has to be in a different cell in a jupyter notebook and indeed that cell has to come after uploadFile.
However, how would I then implement this in a Python file? So a .py file instead of .ipynb