nicolaskruchten / jupyter_pivottablejs

Drag’n’drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js
http://nicolas.kruchten.com/content/2015/09/jupyter_pivottablejs/
Other
687 stars 88 forks source link

Jupyter Notebook Calling pivot_ui() Multiple Instances #65

Closed yifeng021 closed 2 years ago

yifeng021 commented 2 years ago

I am able to call pivot_ui() in Jupyter Notebook, and it works well.

What I want to do is to call pivot_ui() multiple times in a single notebook (may or may not be in the same cell). Each time pivot_ui() is called, I pass different input data into it, and I am hoping to get different pivot charts/tables, each reflecting its corresponding input data.

My example: test1.csv and test2.csv are 2 different data files. I want to create pivot charts in a same notebook page, subsequently. Here's my code: Code

If I run the code for test1.csv only, the I get the chart below. test1

If I run the code for test2.csv only, then I get the chart below. test2

However, if I 'Run All', then the pivot chart for test1.csv was overwritten with data from test2.csv.

Below are my 2 csv files. test1.csv test2.csv

Kindly advise if what I am hoping for is even possible. Thx!

Yifeng

nicolaskruchten commented 2 years ago

Every invocation of pivot_ui() writes a file to disk, and by default it's the same file path, so subsequent calls overwrite the same file. You can set the file path manually with the outfile_path keyword argument. If you set a different path for each call, you should be able to see multiple tables :)

yifeng021 commented 2 years ago

I tried it and it works! Just like you said, so thank you. In some other libraries, I may create a separate object for each invocation, and I create different copies of outputs that way. In this case, since I cannot find an object, I was actually kind of guessing you might have designed one of the input arguments to store a key that uniquely identify one particular invocation, but I wasn't able to figure out outfile_path is that 'key'. Thanks for helping me put 2 and 2 together.