Commit 9d1db11f authored by Romain Casati's avatar Romain Casati
Browse files

Pretty notebook output for SQL queries (troncated output).

parent c23a0eb4
......@@ -33,6 +33,21 @@
await this.pageLoad();
};
html_table (json) {
const max_size = 150;
const columns = json.columns.map((c) => `<th>${c}</th>`).join('');
const head = `<thead><tr style="text-align: right;">${columns}</tr></thead>`;
if( json.values.length >= max_size ) {
const half_length = Math.floor(max_size / 3);
const head = json.values.slice(0, half_length);
const tail = json.values.slice(-half_length);
json.values = head.concat([json.columns.map(() => '')], tail);
}
const values = json.values.map((r) => '<tr>' + r.map((v) => `<td>${v}</td>`).join('') + '</tr>').join('');
const body = `<tbody>${values}</tbody>`;
return `<table class="dataframe" border="1">${head}${body}</table>`;
};
async evalAsync (code, outCallback, errCallback, data=null) {
// force interactivity in all modes
......@@ -46,7 +61,7 @@
result = undefined
else
result = {'text/plain': JSON.stringify(result),
'text/html': result};
'text/html': this.html_table(result[0])};
}
return [result, ++this.execution_count];
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment