Figured it out, Not sure why I got hung up like I did. If anyone else gets stuck: the following class can parse csv files and store as a dataset:
class CSVParser:
def __init__(self, file_in):
self.file = file_in
self.file_string = file_in.getString()
self.rows = [row.split(',') for row in self.file_string.split('\r')]
self.num_cols = max([len(row) for row in self.rows])
self.num_rows = len(self.rows)
self.headers = self.rows[0]
self.data = self.rows[1:]
@property
def extended_headers(self):
headers_output = self.headers
ii = 1
while len(headers_output) < self.num_cols:
headers_output.append('Placeholder{}'.format(ii))
ii += 1
return headers_output
def extend_row(self, row):
row_output = row
while len(row_output) < self.num_cols:
row_output.append(None)
return row_output
@property
def dataset(self):
headers = self.extended_headers
data = [self.extend_row(row) for row in self.data]
return system.dataset.toDataSet(headers, data)
On fileUpload script:
system.perspective.print('file received')
parser = parsers.CSVParser(event.file)
self.getSibling("Table").props.data = parser.dataset