jp3001
January 31, 2020, 9:44am
1
I’ve got a strange error when trying to save a p5.table
tablo= new p5.table;
saveTable(tablo,‘Memory’,‘csv’);
I’ve got the following msg:
Exception has occured
Error: creaheader is not defined
but if I enter ‘html’ instead of ‘csv’ everything is working file and the table is save in the file !!
Pls help !
kll
January 31, 2020, 4:55pm
2
so possibly empty files are not allowed?
need minimum a table structure to make a header line
https://editor.p5js.org/kll/sketches/Ie48wONx
but usually start the other way, from reading a file
-a- create in online editor a subdirectory
/assets/
-b- create inthere a new file ‘Memory.csv’
edit it manually with 2 lines minimum,
one header line
one data line
(or upload the file from you computer )
and in your code just use
https://p5js.org/reference/#/p5/loadTable
function preload() {
table = loadTable('assets/Memory.csv', 'csv', 'header');
}
glv
January 31, 2020, 5:02pm
3
Hello,
I used this example:
https://p5js.org/reference/#/p5/saveTable
I edited it:
let table;
function setup() {
table = new p5.Table();
// table.addColumn('id');
//table.addColumn('species');
//table.addColumn('name');
//let newRow = table.addRow();
// newRow.setNum('id', table.getRowCount() - 1);
//newRow.setString('species', 'Panthera leo');
// newRow.setString('name', 'Lion');
// To save, un-comment next line then click 'run'
saveTable(table, 'new.csv');
}
// Saves the following to a file called 'new.csv':
// id,species,name
// 0,Panthera leo,Lion
It saves a csv file.
This works as well:
saveTable(table, 'new', 'csv');
Google Chrome was used along with https://editor.p5js.org/
1 Like
jp3001
February 3, 2020, 9:33am
4
My table is not empty I am entering valus as follows ::
tablo = new p5.Table();
tablo.addColumn(‘search_key’);
tablo.addColumn(‘counter’);
newRow = tablo.addRow();
newRow.setString('search_key', key_search + "\t");
newRow.setNum('counter', counter);
jp3001
February 3, 2020, 9:38am
5
The strange thing is when I saved the table using :
saveTable(tablo,‘Memory’,‘csv’); I’ve got the error msg
but if I save with:
saveTable(tablo,‘Memory’,‘html’);
the save is saved perfectly !
This strange behaviour is the reason of this post
kll
February 4, 2020, 2:06am
6
so, you see that you got 2 answers what all say:
saveTable(table, 'filename.csv', 'csv');
or
saveTable(table, 'filename.csv');
works,
using the online editor,
( i give you already the link to my test code)
but again minimal test what works:
let table = new p5.Table();
function setup() {
saveTable(table,'Memory','csv');
}
and in my case using win 10 / firefox browser
why you not just give us the link to your
project in the online editor so we can reproduce that error.
1 Like
jp3001
February 4, 2020, 10:00am
7
I finally found the error : the p5.js library file was corrupted !
Now everything is working fine
Thanks to all of you
1 Like
glv
February 4, 2020, 11:27am
8
kll:
so, you see that you got 2 answers what all say:
saveTable(table, 'filename.csv', 'csv');
or
saveTable(table, 'filename.csv');
works,
using the online editor,
I posted these examples along with this reference :
saveTable(table, 'new.csv');
Or:
saveTable(table, 'new', 'csv');
Will save a table as:
new.csv
And adding this:
saveTable(table, 'new.csv', 'csv');
So there are 3 ways to save the table to:
new.csv
’ ’
1 Like