nicolaskruchten/jupyter_pivottablejs

Sorters does not work

kishmus opened this issue · 6 comments

Hi,
I am trying to use sorters with pivot_ui. I get the following error in the browser
"An error occurred rendering the PivotTable UI."

Code as below:
import pandas as pd
import numpy as np
import pivottablejs as pj

linDir = "F:\Operations\MIS\DailyLockedIn\"
linFile = "LockedInDataSheet.xlsx"
outHtml = linDir+"LI.html"

ld = pd.read_excel(linDir+linFile)
pj.pivot_ui(ld, outfile_path=outHtml,
rows=["IPG"], cols=["LOAD_DATE","Parameter"],
aggregatorName="Integer Sum", vals=["AP"],
exclusions={"IPG":["NO IPG","PES-IND"],
"Parameter":["ELAPSED","@ RISK EBD"]},
sorters={"Parameter":["BHC","ERD","EBD","ELAPSED","@ RISK EBD"]}
sort_keys = True
)

Any help is highly appreciated.

Based on your usage of Python code I'm assuming you're using the Jupyter binding... It's not possible to use sorters with the Jupyter binding unfortunately: only JSON-serializable parameters can be used.

(i've just updated the ReadMe here https://github.com/nicolaskruchten/jupyter_pivottablejs to make that clearer, sorry for any confusion!)

Thanks Nicolas.
Yes. I am using Jupyter binding.

Based on your usage of Python code I'm assuming you're using the Jupyter binding... It's not possible to use sorters with the Jupyter binding unfortunately: JSON-serializable parameters can be used.

Hi Nicolas, could you show me an example on this?
i try:

sort_list='{"col_A": ["B","D","A","C"] }'
j = json.loads((sort_list))
pivot_ui(df,sorters=j)

but it comes out an error:
An error occurred rendering the PivotTable UI.

emmm, any ideas? some examples would be better.

Sorry, I've edited my reply to add the missing word "only": only JSON-serializable parameters can be used. Meaning functions simply cannot be passed through as they are not JSON-serializable.

Hi Nicols, thanks for your reply.