Skip to content

Commit

Permalink
incorporating feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaskruchten committed May 7, 2017
1 parent e86f43e commit 05a4715
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pivottablejs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
template = """
TEMPLATE = """
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PivotTable.js</title>
<!-- external libs from cdnjs -->
Expand Down Expand Up @@ -47,27 +48,30 @@
$("#output").pivotUI(
$.csv.toArrays($("#output").text()),
{
$.extend({
renderers: $.extend(
$.pivotUtilities.renderers,
$.pivotUtilities.c3_renderers,
$.pivotUtilities.d3_renderers,
$.pivotUtilities.export_renderers
),
hiddenAttributes: [""]
}
}, %(kwargs)s)
).show();
});
</script>
<div id="output" style="display: none;">%s</div>
<div id="output" style="display: none;">%(csv)s</div>
</body>
</html>
"""

from IPython.display import IFrame
import json

def pivot_ui(df, outfile_path = "pivottablejs.html", width="100%", height="500"):
def pivot_ui(df, outfile_path = "pivottablejs.html", width="100%", height="500",
**kwargs):
with open(outfile_path, 'w') as outfile:
outfile.write(template % df.to_csv())
outfile.write(TEMPLATE %
dict(csv=df.to_csv(), kwargs=json.dumps(kwargs)))
return IFrame(src=outfile_path, width=width, height=height)

0 comments on commit 05a4715

Please sign in to comment.