Upload csv
import asyncio
import panel as pn
import pandas as pd
from panel.io.pyodide import show
from io import StringIO
fileInput = pn.widgets.FileInput(accept='.csv')
uploadButton = pn.widgets.Button(name='Upload', button_type = 'primary')
df = pd.DataFrame()
table = pn.widgets.Tabulator(pagination='remote', page_size=10)
def process_file(event):
if fileInput.value is not None:
table.value = pd.read_csv(io.BytesIO(fileInput.value))
document.getElementById('table').style.display = 'block'
uploadButton.on_click(process_file)
def get_csv():
return io.BytesIO(table.value.to_csv().encode())
file_download_csv = pn.widgets.FileDownload(filename="data.csv", callback=get_csv, button_type="primary")
await show(fileInput, 'fileinput')
await show(uploadButton, 'upload')
await show(table, 'table')
await show(file_download_csv, 'download')