Update: Dash Pivottable is now an official library, published on PyPi and contributed to CRAN! You can read the announcement for Python v0.0.1 here, and the release post for R v0.0.2 here.
I found out about pivottable.js last summer, and I really liked the idea of a library for interactive data exploration in JS, along with built-in aggregations (sums, average, count) and displays (table, scatter plots, bar charts), all done through an UI component.
I haven’t had the chance to try it out, so today I decided to get started by making it into a Dash component. Thus, I made this dash wrapping of the react-pivottable library (maintained by Plotly, and created by Nicholas who also made pivottable.js; awesome work!).
Thank you! This is based on react-pivottable, so I would recommend taking a look at how it optimizing rendering for very large datasets. Otherwise, using Pandas and Numpy to preprocess your dataset so that the table transmitted at the end is smaller could be helpful too!
Took a look - turns out that all the pivoting happens client-side, and server-side integration is not great; this makes sense from a React-ive point of view but definitely not from a large-data-workability viewpoint. Sadly the design just doesn’t work for me.
My data is between 15M and 125M records, held in a pretty powerful server, accessed through a Dash app for business reporting. Right now it’s possible to interactively pivot server-side by generating a pivot table and rendering it with table.to_html() and making pivot charts with matplotlib before rendering them as images in the Dash. It’s not optimal though.
It could be interesting to hack out a component that mimics react-pivottable's pivoting and visualization logic on the server-side in order to make the larger data realistic.
Very cool, thanks a lot. I am attempting to alter styling by using an external stylesheet (Dash(…, external_stylesheets=‘my.css’)) but it seems as though many css classes are defined downstream, and I cannot override them. I have had limited success altering fontsizes and padding of various elements.
This is fantastic, thanks very much for developing. I know this isn’t an official dash add-on yet - are there any plans for it to get the full dash treatment?
In the meantime (and this isn’t a begging request for someone to completely overhaul the code…more a question of the underlying pivottable.js functionality), is it possible to generate sub-totals per row, e.g. turn the following:
What if I want to sum/count/Average not just 1 column, but two or more? For example, for each gender I want to see sum/count/average of Total Bills and also of Tips.
Is that possible? If not - any suggestions how I could add myself?
Any lucky to solve this? I also met the same issue. I want to sum/count for aggfuc, not sure how to fix it. If you know how to fix it, could you share it with me? Thanks a lot.
I am a newbie to Dash and one of my primary requirement is to incorporate a pivot table. I refereed to the github link, but could not figure out how to include it in my project so I would use it in my dash application. Any guidance is appreciated.
I was in the same situation not so long ago, and I manage to integrate it in my project by downloading the dash_pivottable folder and copying it in my project folder. After you just have to import it at the beginning of your python file. You should have a look at the usage.py in the GitHub to understand how does it work.
Hi, like kirk77, I am struggling to understand how to install and use the package. I tried to follow easy_panda’s advice, but still have not succeeded. is anyone able to point me in the right direction for how to ‘Make sure to clone this project, create a venv and install requirements:’?
I’m having difficulty to be able to pull the “rows” values from my pivot table (yellow).
As seen from the picture, I’m making pivot_id(red) change every time when a new filtered dataframe is passed in as an input because the pivot-table will not update automatically with a constant id value.
Since I now can’t pass in the pivot-table’s id directly into my RSV_Data Table callback , I’m storing my “testa” (blue) in a hidden html.Div separately then try to use it instead in the Input’s id; and this is not working.
I don’t see the full code, but I’m assuming here the component “testa” is a html.Div. In this case it’s not possible to update its rows property since it does not exist. You will need to update the pivot_id directly.
Ofc, this will throw an error if it happens. To bypass it, you can use pattern matching to find all instances of a class of components. For example, you can assign your table id={'type': 'pivottable', 'index': 0}, and later in a callback, you can pattern match
@app.callback(
Output(...),
[Input({'type': 'pivottable', 'index': ALL}, 'rows')]
)
def update_rows(tables):
if len(tables) == 0:
# No table exists yet
return ...
else:
# There's at least one pivottable now
...
This is incredibly powerful and useful, thank you.
I’m having trouble formatting my data to be read into the template script.
I see that the data file tips.Rdata is a list in R - I assume that i turn my table into a dict for this to work, but pandas.DataFrame.to_dict is throwing up a memory error for me.
can i just turn my data into a list in r and save down like the tips.Rdata file?
any advice on this would be greatly appreciated. (i’m much more comfortable in R than Python)