Giter VIP home page Giter VIP logo

dash-pivottable's Introduction

CRAN status

Dash Pivottable

Dash Pivottable is a Dash component wrapping the react-pivottable library, created by Nicolas Kruchten. It lets you build interactive pivot tables using purely Python.

pivot table demo

Getting Started

Install with virtualenv

First, install virtualenv with pip install virtualenv.

Then, make sure to clone this project, create a venv and install requirements:

git clone https://github.com/plotly/dash-pivottable.git
cd dash_pivottable
python3 -m venv ./venv
source venv/bin/activate
pip install -r requirements.txt

And simply run the example in the venv:

python usage.py

References

The following parameters can be modified:

  • id (string; optional): The ID used to identify this component in Dash callbacks
  • data (list; optional): The input data
  • hiddenAttributes (list; optional): contains attribute names to omit from the UI
  • hiddenFromAggregators (list; optional): contains attribute names to omit from the aggregator arguments dropdowns
  • hiddenFromDragDrop (list; optional): contains attribute names to omit from the drag'n'drop portion of the UI
  • menuLimit (number; optional): maximum number of values to list in the double-click menu
  • unusedOrientationCutoff (number; optional): If the attributes' names' combined length in characters exceeds this value then the unused attributes area will be shown vertically to the left of the UI instead of horizontally above it. 0 therefore means 'always vertical', and Infinity means 'always horizontal'.

The following props can be used as an input to callbacks, but can't be modified:

  • cols (list; optional): Which columns are currently in the column area
  • colOrder (string; optional): The order in which column data is provided to the renderer, must be one of "key_a_to_z", "value_a_to_z", "value_z_to_a", ordering by value orders by column total
  • rows (list; optional): Which rows is currently inside the row area.
  • rowOrder (string; optional): The order in which row data is provided to the renderer, must be one of "key_a_to_z", "value_a_to_z", "value_z_to_a", ordering by value orders by row total
  • aggregatorName (string; optional): Which aggregator is currently selected. E.g. Count, Sum, Average, etc.
  • vals (list; optional): Attribute names used as arguments to aggregator (gets passed to aggregator generating function)
  • rendererName (string; optional): Which renderer is currently selected. E.g. Table, Line Chart, Scatter
  • valueFilter (dictionnary; optional): Object whose keys are attribute names and values are objects of attribute value-boolean pairs which denote records to include or exclude from computation and rendering; used to prepopulate the filter menus that appear on double-click

Default Values:

  • menuLimit: 500
  • unusedOrientationCutoff: 85
  • hiddenAttributes: []
  • hiddenFromAggregators: []
  • hiddenFromDragDrop: []

FAQ

You can find the following FAQs in contributing.md:

dash-pivottable's People

Contributors

cdammanintopix avatar gvwilson avatar rpkyle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dash-pivottable's Issues

PivotTable will not accept style arg

Screen Shot 2019-07-13 at 10 34 49 PM

Adding a style command to set the width has no effect on graph or iframe.

Example:

#Pivot table test
html.Div(dash_pivottable.PivotTable(
id='table',
data=data,
cols=['Day of Week'],
colOrder="key_a_to_z",
rows=['Party Size'],
rowOrder="key_a_to_z",
rendererName="Table",
aggregatorName="Average",
vals=["Total Bill"],
valueFilter={'Day of Week': {'Thursday': False}},
),
style= {'width': 300};
),
# Row 4

Colored Scatter plot

Hi,

Thanks for the great library! I was wondering if it were possible to have scatter plots colored by group in dash-pivottable?
For instance, in this example i made in dash-pivottable, I plot two columns with aggregation = first(status). Ideally I would like to see the color legend as displayed in image 2 .If yes, how would I do this? Thanks.

image

image

How to retain filter in multiple tabs application

I use dash_pivottable in a multiple tabs DASH application, but the filter set in pivot is gone after tab switching. I have tried dcc.tabs persistence=True, persistence_type='session'/'local'/'memory', but still cannot retain filter config after tab switching. The config of cols, rows, value or aggregatorName can be retained after tab switching, only filter is gone. Is there any way to retain the filter please?

The `vals` property is not updated when accessed through callback

Description

The vals property is not updated when accessed through a callback (unlike other properties such as cols and rows).

This would be really useful to maintain state between updates to the data of the pivot table. Currently, vals always has the original value.

Steps/Code to Reproduce

Run the following code and change the quantity being plotted from "Total Bill" to "Tips". The output vals quantity will not change and will continue to report "Total Bill".

import dash
from dash.dependencies import Input, Output
import dash_html_components as html
import dash_pivottable

from data import data

app = dash.Dash(__name__)
app.title = 'My Dash example'

app.layout = html.Div([
    dash_pivottable.PivotTable(
        id='table',
        data=data,
        cols=['Day of Week'],
        colOrder="key_a_to_z",
        rows=['Party Size'],
        rowOrder="key_a_to_z",
        rendererName="Grouped Column Chart",
        aggregatorName="Average",
        vals=["Total Bill"],
        valueFilter={'Day of Week': {'Thursday': False}}
    ),
    html.Div(
        id='output'
    )
])


@app.callback(Output('output', 'children'),
              [Input('table', 'cols'),
               Input('table', 'rows'),
               Input('table', 'rowOrder'),
               Input('table', 'colOrder'),
               Input('table', 'aggregatorName'),
               Input('table', 'rendererName'),
               Input('table', 'vals')])
def display_props(cols, rows, row_order, col_order, aggregator, renderer, vals):
    return [
        html.P(str(cols), id='columns'),
        html.P(str(rows), id='rows'),
        html.P(str(row_order), id='row_order'),
        html.P(str(col_order), id='col_order'),
        html.P(str(aggregator), id='aggregator'),
        html.P(str(renderer), id='renderer'),
        html.P(str(vals), id='vals'),
    ]


if __name__ == '__main__':
    app.run_server(debug=True)

Versions

Dash 1.19.0
Dash Core Components 1.1.2
Dash HTML Components 1.15.0
Dash Renderer 1.9.0
Dash Pivot Table 0.0.2

Add a new Renderer

hi ,
how to add a new renderer like violin plot or different types of plots which plotly supports .
Where I have to go and make the change ?

Thanks.

Styling Dash Pivottable

I am implementing the Dash Pivottable as part of a larger dashboard but would like to see the ability to define or change the default colors and overall styling.
Additionally, is the text that appears at the bottom of the of the pivot table essential? I would like this to be hidden if possible.
I apologize if this is the wrong forum for this type of request.

dash_pivottable was not found when executing usage.py from outside main folder

Hi @xhlulu, really glad you built this.

I've been trying to get your example working with an existing flask app. I tried to follow the plotly example for integrating a dash app with a flask app with the Werkzeug DispatcherMiddleware (https://dash.plot.ly/integrating-dash). This is how i imported the dash app from usage.py:

from werkzeug.serving import run_simple
from flask_app.app import app as flask_app
from dash_pivottable.usage import app as dash_app

application = DispatcherMiddleware(
        flask_app, {
            '/dash': dash_app.server
            }
        )

if __name__ == '__main__':
    run_simple('localhost', 8080, application)
Error: dash_pivottable was not found.
    at Object.resolve (registry.js:17)
    at q (TreeContainer.js:226)
    at G (TreeContainer.js:263)
    at TreeContainer.js:303
    at connect.js:110
    at i.updateMergedPropsIfNeeded (connect.js:224)
    at i.render (connect.js:348)
    at ce ([email protected]?v=1.0.0&m=1562232467:98)
    at qg ([email protected]?v=1.0.0&m=1562232467:97)
    at hi ([email protected]?v=1.0.0&m=1562232467:104)```

Let me know if you need more information!

Pivottable doesn't get updated in successive callbacks

This works:

import dash
import dash_html_components as html
from dash.dependencies import Input, Output

import dash_pivottable

app = dash.Dash(__name__)

app.layout = html.Div(
    [html.Button("Rfresh", id="button"), html.Div(id="pivottable_div")]
)


@app.callback(Output("pivottable_div", "children"), [Input("button", "n_clicks")])
def refresh_pivottable(n_clicks):
    if n_clicks:
        print(n_clicks)
        return [
            html.Div(str(n_clicks)),
            dash_pivottable.PivotTable(data=[["a"], [n_clicks]], cols=["a"])
            if n_clicks % 2 == 1
            else "a",
        ]


if __name__ == "__main__":
    app.run_server(debug=False)

This doesn't:

import dash
import dash_html_components as html
from dash.dependencies import Input, Output

import dash_pivottable

app = dash.Dash(__name__)

app.layout = html.Div(
    [html.Button("Rfresh", id="button"), html.Div(id="pivottable_div")]
)


@app.callback(Output("pivottable_div", "children"), [Input("button", "n_clicks")])
def refresh_pivottable(n_clicks):
    if n_clicks:
        print(n_clicks)
        return [
            html.Div(str(n_clicks)),
            dash_pivottable.PivotTable(data=[["a"], [n_clicks]], cols=["a"])
            # if n_clicks % 2 == 1
            # else "a",
        ]


if __name__ == "__main__":
    app.run_server(debug=False)

The only difference of them is the 2 commented lines.

My environment:

windows7 64bit
python3.7 64bit
dash 1.4.1

Please run the cases to see the difference. Many thanks.

Can't get state value of valueFilter

Description

I need to get valueFilter which changed by user
But instead got {}

Steps/Code to Reproduce

from dash import html, Output, Input, State
import dash_pivottable

app = dash.Dash(__name__)
server = app.server
import dash_bootstrap_components as dbc
app.layout = html.Div(children=[
    dbc.Button('Press',id='button'),
    html.Div(id="my-div",children=
    [
        dash_pivottable.PivotTable(id="pivot",
        data=[
            ['Animal', 'Count', 'Location'],
            ['Zebra', 5, 'SF Zoo'],
            ['Tiger', 3, 'SF Zoo'],
            ['Zebra', 2, 'LA Zoo'],
            ['Tiger', 4, 'LA Zoo'],
        ],
        cols=["Animal"],
        rows=["Location"],
        vals=["Count"],
        valueFilter={}

    )]
)])

@app.callback(
    Output("my-div", 'children'),
    Input('button', 'n_clicks'),
    State("pivot","cols"),
    State("pivot", "rows"),
    State("pivot", "vals"),
    State("pivot", "valueFilter"),
)
def refresh(n_clicks,cols,rows,vals,filter):
    print(filter)
    print(f"Click={n_clicks}")
    ret=html.Div(children=dash_pivottable.PivotTable(
        id=f"pivot",
        data=[
            ['Animal', 'Count', 'Location'],
            ['Zebra', n_clicks, 'SF Zoo'],
            ['Tiger', n_clicks, 'SF Zoo'],
            ['Zebra', n_clicks, 'LA Zoo'],
            ['Tiger', n_clicks, 'LA Zoo'],
        ],
        cols=cols,
        rows=rows,
        vals=vals,
        valueFilter=filter
    ),id=f"pivot_div_{n_clicks}",)
    return ret
if __name__ == "__main__":
    app.run_server(debug=True)

Expected Results

Actual Results

Versions

Is it possible to export to excel?

Hi,

This is handy and end user will probably ask for how to export the pivoted data. Is export to excel an option? Or it depends on react-pivotable to implement certain interface?

Option to show only table/chart

Is it possible hide the pivot table/UI controls, keeping only the pivot table/chart? I saw Nicholas's reply to the same question on the react-pivottable project but after changing <PivotTableUI ... /> to <PivotTable ... /> in PivotTable.react.js and generating a new PivotTable.py, the web page fails to load.

Remove dash_pivottable.dev.js from package

The dash_pivottable.dev.js file appears currently unused by either the Python or R packages, and is approximately 20 MB in size.

If possible, I'd suggest only building this additional JS via webpack when needed. For example, in dash-renderer's package.json we have

    "build:js": "webpack --build release",
    "build:dev": "webpack --build local",

which we use to control whether source maps are generated as well.

This recently caused friction with submitting the package to CRAN:

Thanks, we see:

Size of tarball: 5900811 bytes

Not more than 5 MB for a CRAN package, please.

Please fix and resubmit.

If we're able to make this change, the uncompressed R package size will plummet to 3 MB from over 20 MB, and the compressed archive will be approximately 1 MB.

@xhlulu @Marc-Andre-Rivet

Boolean values set to valueFilter do not matter

Whether or not you set a value to True or False, it is eliminated from the active display:

From the sample:

valueFilter={'Day of Week': {'Thursday': False}}

leads to the same behavior as:

valueFilter={'Day of Week': {'Thursday': True}}

Perhaps I am not using this correctly? Thanks for sharing this excellent project

How can i plot n pivot tables in dash plotly python?

Description

I want multiple pivot tables to be generated on the dash dashboard. The number of pivot tables is to be decided by the user input. Or is there a way to add a 'add pivot table' button and on each click a new pivot able is generated on the dashboard?

Steps/Code to Reproduce

Expected Results

Actual Results

Versions

npm `prepublish` script is breaking CircleCI tests due to Python dependency

Seems like when you run npm install, "prepublish": "npm run validate-init" gets called, which in turns causes this to be called: "validate-init": "python _validate_init.py".

Since python3 is not included with the node image of CircleCI, it's annoying to create a venv in python 2 and run _validate_init.py just for this. We might consider removing _validate_init.py from prepublish in the future.

`venv/Scripts/activate` not working in setup -- change to venv activate line

First of all, this thing is AWESOME!! Thank you so much!!

Right now, you have the setup commands to be:

$ git clone https://github.com/xhlulu/dash_pivottable.git
$ cd dash_pivottable
$ virtualenv venv
$ venv/Scripts/activate
$ pip install -r requirements.txt

$ python usage.py

BUT, I had some issues with this, and it wasn't getting past the third step. In the end, I needed to run these instead:

$ git clone https://github.com/xhlulu/dash_pivottable.git
$ cd dash_pivottable
$ virtualenv venv
$ source venv/bin/activate    # Just change this line a bit
$ pip install -r requirements.txt

$ python usage.py

# Then, to deactivate, just
$ deactivate

And, of course for future uses:

$ cd dash_pivottable
$ source venv/bin/activate
$ python usage.py

# Do stuff
$ deactivate

I'm running on MacOS with Mojave, vers 10.14.3.

Thanks again!

Custom aggregator: weighted average

I would like to implement a weighted average using a fixed column as the weight value. That is, I could specify in advance that I want a specific column to serve as the weight. I am happy to alter the source of either dash-pivottable or react-pivottable but I'm not sure where to begin.

Does someone have a suggestion of how to or an example of implementing custom aggregation functions?

Thanks,

Matt

Remove Totals column and row

Hi, is there a way to exclude Totals column and row, and set a customized order of data in the pivot table?
Thanks!

exposing clickCallback (tableOptions)

Is there a way to expose clickCallback to be able to do drilldowns? This is an added feature in react-pivottable. The javascript call for it looks like from the react demo is;

tableOptions: {
clickCallback: function(e, value, filters, pivotData) {
var names = [];
pivotData.forEachMatchingRecord(filters, function(
record
) {
names.push(record.Meal);
});
alert(names.join('\n'));

Specify plot size

Hi.
I am integrating PivotTable with other components in the same screen. I have already included a scrollable DIV
as suggested in #7 but I would really like to be able to specify the size of the plots. Due to the nature of my data I get very large plots that would be much better if rendered in a smaller format.

The code would be something like this:

    return  html.Div(id='div_pivot', children=[
                dash_pivottable.PivotTable(
                    id='Tabela',
                    data=data,
                    cols=dic_pivot['cols'],
                    #colOrder='key_a_to_z',
                    rows=dic_pivot['rows'],
                    #rowOrder='key_a_to_z',
                    rendererName='Table',
                    aggregatorName='Sum',
                    vals=dic_pivot['vals'],
                    valueFilter={},
                    hiddenFromAggregators=dic_pivot['hiddenFromAggregators'],
                    hiddenFromDragDrop=dic_pivot['vals'],
                    hiddenAttributes=hidden,                     
#The line below is a suggestion and causes an error in the current version
                    rendererOptions={'autosize':True, 'width':700, 'height':450,},
                ),], style={'height':'450px', 'overflow':'scroll', 'resize':'both'} )

rendererOptions in dash pivot table

Is it possible to add rendererOptions in the input.
I am trying to build a pivot table with heatmap
where I want color coding for values in the table.

I just want conditional formatting of styling in table or heatmaps.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.