Giter Club home page Giter Club logo

react-pivottable's Introduction

react-pivottable

react-pivottable is a React-based pivot table library with drag'n'drop functionality. It is a React port of the jQuery-based PivotTable.js by the same author.

react-pivottable is part of Plotly's React Component Suite for building data visualization Web apps and products.

What does it do & where is the demo?

react-pivottable's function is to enable data exploration and analysis by summarizing a data set into table or Plotly.js chart with a true 2-d drag'n'drop UI, very similar to the one found in older versions of Microsoft Excel.

A live demo can be found here.

screencap

How can I use it in my project?

Drag'n'drop UI with Table output only

Installation is via NPM and has a peer dependency on React:

npm install --save react-pivottable react react-dom

Basic usage is as follows. Note that PivotTableUI is a "dumb component" that maintains essentially no state of its own.

import React from 'react';
import ReactDOM from 'react-dom';
import PivotTableUI from 'react-pivottable/PivotTableUI';
import 'react-pivottable/pivottable.css';

// see documentation for supported input formats
const data = [['attribute', 'attribute2'], ['value1', 'value2']];

class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = props;
    }

    render() {
        return (
            <PivotTableUI
                data={data}
                onChange={s => this.setState(s)}
                {...this.state}
            />
        );
    }
}

ReactDOM.render(<App />, document.body);

Drag'n'drop UI with Plotly charts as well as Table output

The Plotly react-plotly.js component can be passed in via dependency injection. It has a peer dependency on plotly.js.

Important: If you build your project using webpack, you'll have to follow these instructions in order to successfully bundle plotly.js. See below for how to avoid having to bundle plotly.js.

npm install --save react-pivottable react-plotly.js plotly.js react react-dom

To add the Plotly renderers to your app, you can use the following pattern:

import React from 'react';
import PivotTableUI from 'react-pivottable/PivotTableUI';
import 'react-pivottable/pivottable.css';
import TableRenderers from 'react-pivottable/TableRenderers';
import Plot from 'react-plotly.js';
import createPlotlyRenderers from 'react-pivottable/PlotlyRenderers';

// create Plotly renderers via dependency injection
const PlotlyRenderers = createPlotlyRenderers(Plot);

// see documentation for supported input formats
const data = [['attribute', 'attribute2'], ['value1', 'value2']];

class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = props;
    }

    render() {
        return (
            <PivotTableUI
                data={data}
                onChange={s => this.setState(s)}
                renderers={Object.assign({}, TableRenderers, PlotlyRenderers)}
                {...this.state}
            />
        );
    }
}

ReactDOM.render(<App />, document.body);

With external plotly.js

If you would rather not install and bundle plotly.js but rather get it into your app via something like <script> tag, you can ignore react-plotly.js' peer-dependcy warning and handle the dependency injection like this:

import React from 'react';
import PivotTableUI from 'react-pivottable/PivotTableUI';
import 'react-pivottable/pivottable.css';
import TableRenderers from 'react-pivottable/TableRenderers';
import createPlotlyComponent from 'react-plotly.js/factory';
import createPlotlyRenderers from 'react-pivottable/PlotlyRenderers';

// create Plotly React component via dependency injection
const Plot = createPlotlyComponent(window.Plotly);

// create Plotly renderers via dependency injection
const PlotlyRenderers = createPlotlyRenderers(Plot);

// see documentation for supported input formats
const data = [['attribute', 'attribute2'], ['value1', 'value2']];

class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = props;
    }

    render() {
        return (
            <PivotTableUI
                data={data}
                onChange={s => this.setState(s)}
                renderers={Object.assign({}, TableRenderers, PlotlyRenderers)}
                {...this.state}
            />
        );
    }
}

ReactDOM.render(<App />, document.body);

Properties and layered architecture

  • <PivotTableUI {...props} />
    • <PivotTable {...props} />
      • <Renderer {...props} />
        • PivotData(props)

The interactive component provided by react-pivottable is PivotTableUI, but output rendering is delegated to the non-interactive PivotTable component, which accepts a subset of its properties. PivotTable can be invoked directly and is useful for outputting non-interactive saved snapshots of PivotTableUI configurations. PivotTable in turn delegates to a specific renderer component, such as the default TableRenderer, which accepts a subset of the same properties. Finally, most renderers will create non-React PivotData object to handle the actual computations, which also accepts a subset of the same props as the rest of the stack.

Here is a table of the properties accepted by this stack, including an indication of which layer consumes each, from the bottom up:

Layer Key & Type Default Value Description
PivotData data
see below for formats
(none, required) data to be summarized
PivotData rows
array of strings
[] attribute names to prepopulate in row area
PivotData cols
array of strings
[] attribute names to prepopulate in cols area
PivotData vals
array of strings
[] attribute names used as arguments to aggregator (gets passed to aggregator generating function)
PivotData aggregators
object of functions
aggregators from Utilites dictionary of generators for aggregation functions in dropdown (see original PivotTable.js documentation)
PivotData aggregatorName
string
first key in aggregators key to aggregators object specifying the aggregator to use for computations
PivotData valueFilter
object of arrays of strings
{} 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
PivotData sorters
object or function
{} accessed or called with an attribute name and can return a function which can be used as an argument to array.sort for output purposes. If no function is returned, the default sorting mechanism is a built-in "natural sort" implementation. Useful for sorting attributes like month names, see original PivotTable.js example 1 and original PivotTable.js example 2.
PivotData rowOrder
string
"key_a_to_z" 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
PivotData colOrder
string
"key_a_to_z" 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
PivotData derivedAttributes
object of functions
{} defines derived attributes (see original PivotTable.js documentation)
Renderer <any> (none, optional) Renderers may accept any additional properties
PivotTable renderers
object of functions
TableRenderers dictionary of renderer components
PivotTable rendererName
string
first key in renderers key to renderers object specifying the renderer to use
PivotTableUI onChange
function
(none, required) function called every time anything changes in the UI, with the new value of the properties needed to render the new state. This function must be hooked into a state-management system in order for the "dumb" PivotTableUI component to work.
PivotTableUI hiddenAttributes
array of strings
[] contains attribute names to omit from the UI
PivotTableUI hiddenFromAggregators
array of strings
[] contains attribute names to omit from the aggregator arguments dropdowns
PivotTableUI hiddenFromDragDrop
array of strings
[] contains attribute names to omit from the drag'n'drop portion of the UI
PivotTableUI menuLimit
integer
500 maximum number of values to list in the double-click menu
PivotTableUI unusedOrientationCutoff
integer
85 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'.

Accepted formats for data

Arrays of objects

One object per record, the object's keys are the attribute names.

Note: missing attributes or attributes with a value of null are treated as if the value was the string "null".

const data = [
    {
        attr1: 'value1_attr1',
        attr2: 'value1_attr2',
        //...
    },
    {
        attr1: 'value2_attr1',
        attr2: 'value2_attr2',
        //...
    },
    //...
];

Arrays of arrays

One sub-array per record, the first sub-array contains the attribute names. If subsequent sub-arrays are shorter than the first one, the trailing values are treated as if they contained the string value "null". If subsequent sub-arrays are longer than the first one, excess values are ignored. This format is compatible with the output of CSV parsing libraries like PapaParse.

const data = [
    ['attr1', 'attr2'],
    ['value1_attr1', 'value1_attr2'],
    ['value2_attr1', 'value2_attr2'],
    //...
];

Functions that call back

The function will be called with a callback that takes an object as a parameter.

Note: missing attributes or attributes with a value of null are treated as if the value was the string "null".

const data = function(callback) {
    callback({
        "attr1": "value1_attr1",
        "attr2": "value1_attr2",
        //...
    });
    callback({
        "attr1": "value2_attr1",
        "attr2": "value2_attr2",
        //...
    };
    //...
};

react-pivottable's People

Contributors

atenhar avatar gvwilson avatar jackparmer avatar jfurie avatar nicolaskruchten avatar nselikoff avatar steventebrinke avatar tarekrached 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-pivottable's Issues

Optimizing

Hello! Are there ways to optimize rendering of table if I have a json file with more than 1000 items?

[bug] onChange is passing more than fresh component can accept

I made pivottable persistent and the problem arises that after I reload app and the attributes are fetched from database and set on component I'm getting this error:
this.props.aggregators[this.props.aggregatorName] is not a function.

What's most interesting is the fact that the state from the database is identical to the one that I had before reloading the app (confirmed).

The workaround I use is to just save following attributes:

['data', 'rows', 'cols', 'aggregatorName', 'vals', 'rendererName', 'sorters', 'plotlyOptions']

But that's just a hack/workaround and either onChange shouldn't return what it then cannot accept on fresh component, or fresh component should be able to parse these attributes.

For reference, here's the example state that causes the component to crash:

{
  "data": [
    [
      "technology",
      "provider",
      "avg signal"
    ],
    [
      "3G",
      "Orange",
      179
    ],
    [
      "3G",
      "Telefonica",
      179
    ],
    [
      "3G",
      "Verizon",
      179
    ],
    [
      "4G",
      "Orange",
      199
    ],
    [
      "4G",
      "Verizon",
      198
    ],
    [
      "H+",
      "Orange",
      175
    ],
    [
      "H+",
      "Telefonica",
      174
    ],
    [
      "H+",
      "Verizon",
      173
    ]
  ],
  "aggregators": {},
  "cols": [
    "provider"
  ],
  "rows": [
    "technology"
  ],
  "vals": [
    "avg signal"
  ],
  "aggregatorName": "Average",
  "sorters": {},
  "valueFilter": {},
  "rowOrder": "key_a_to_z",
  "colOrder": "key_a_to_z",
  "derivedAttributes": {},
  "rendererName": "Table",
  "renderers": {},
  "hiddenAttributes": [],
  "hiddenFromAggregators": [],
  "hiddenFromDragDrop": [],
  "unusedOrientationCutoff": 85,
  "menuLimit": 500
}

Updating PivotTableUI prop does not always force a re-render of child renderer

I'm trying to create what amounts to my own version of Plotly's react-chart-editor. In doing so, I'm passing a layout prop to my component, which I then include in my PlotlyRenderer.js for the final render. Pretty straightforward. However, updates to layout (changes in chart title, etc.) propagate only to the first PivotTableUI configuration. If I change the configuration (pivot the data), subsequent changes to layout do not propagate to the child plot renderer.

My solution to this is to add a key to the main PivotTableUI component, consisting of the stringified version of the layout object. I.e., <PivotTableUI key={JSON.stringify(layout)} ...otherProps />. This works, but I'm not sure if it's correct. If it is correct, perhaps this should be done within the PivotTableUI component itself? An alternative might be to use componentWillReceiveProps and shouldComponentUpdate?

Maintain the state of the pivot table even after refreshing in react ?

Hi Guys,

It is a Question.

Basically i want to main the state of the component even after refreshing. Here is my code

import React, { Component } from 'react';
import tips from './tips';
import PivotTableUI from 'react-pivottable/PivotTableUI';
import PivotTable from 'react-pivottable/PivotTable';
import 'react-pivottable/pivottable.css';
import TableRenderers from 'react-pivottable/TableRenderers';
import Plot from 'react-plotly.js';
import createPlotlyRenderers from 'react-pivottable/PlotlyRenderers';
import AWS from 'aws-sdk';

const PlotlyRenderers = createPlotlyRenderers(Plot);


class App extends Component {
  state = {
    pivotState: {
      data:  [["Name", "CreationDate"]],
      rows: ['Name'],
      cols: ['Humanize'],
      aggregatorName: 'Count',
      rendererName: 'Grouped Column Chart',
  plotlyOptions: {width: 500, height: 500}
  }
  };

 handleClick = () => {
                this.setState(
                  {
                    pivotState: {
                      data: tips,
                      rows: ['Payer Gender'],
                      cols: ['Party Size'],
                      aggregatorName: 'Count',
                      rendererName: 'Grouped Column Chart',
                  plotlyOptions: {width: 600, height: 500}
                  }
                  });
        }

    componentDidMount() {
           console.log("Hi guys")
          }

render() {
    //console.log(this.state)
  return (
    <div styles="width=50px">
      <PivotTable
               //  data={this.state.pullResults.body || []}
                onChange={s => this.setState({pivotState: s})}
                renderers={Object.assign({}, TableRenderers, PlotlyRenderers)}
                {...this.state.pivotState}
            />
            
            
      <button onClick={this.handleClick}>Get results</button>
    </div>

  );
  }
}

export default App;

My tips data file

["Total Bill","Tip","Payer Gender","Payer Smoker","Day of Week","Meal","Party Size"],
  [16.99,1.01,"Female","Non-Smoker","Sunday","Dinner",2],
  [10.34,1.66,"Male","Non-Smoker","Sunday","Dinner",3],
  [21.01,3.5,"Male","Non-Smoker","Sunday","Dinner",3],
  [23.68,3.31,"Male","Non-Smoker","Sunday","Dinner",2],
  [24.59,3.61,"Female","Non-Smoker","Sunday","Dinner",4],
  [25.29,4.71,"Male","Non-Smoker","Sunday","Dinner",4] ]

Above code will show me the empty graph in the DOM first and after hitting button it will render the results.
These results are perishing after refresh but i want to retain same state even after refresh . The update should happen only after i hit the Button.

I had googled for this they say i need to use localstorage for this. But even in localstorage i need to pass the state as JSON.stringify something like this JSON.parse( localStorage.getItem( "pivotstate" ) ); i dont know how to pass pivotstate here.

Any help is appreciated.
Thanks

Display a colunm and sort with another

First of all, great project.

I'm having an issue with the follwing image
image

the domain rules is about size of clothes, here in Brazil we have P M G GG like S, M, L, XL. So I needed to render this sizes on right order.

I can't find any props to render on this way.

RangeError: Maximum call stack size exceeded

0.4.0
0.9.0

i have about 16xxx array items, it looks like if i use prepopulate in row, col with large records that will cause "RangeError: Maximum call stack size exceeded".

    at redColorScaleGenerator (modules.js?hash=78a89e3471e79d692de4a54892c3d20fdd4b55e0:4593)
    at TableRenderer.render (modules.js?hash=78a89e3471e79d692de4a54892c3d20fdd4b55e0:4647)
    at finishClassComponent (modules.js?hash=78a89e3471e79d692de4a54892c3d20fdd4b55e0:106718)
    at updateClassComponent (modules.js?hash=78a89e3471e79d692de4a54892c3d20fdd4b55e0:106686)
    at beginWork (modules.js?hash=78a89e3471e79d692de4a54892c3d20fdd4b55e0:107311)
    at performUnitOfWork (modules.js?hash=78a89e3471e79d692de4a54892c3d20fdd4b55e0:110143)
    at workLoop (modules.js?hash=78a89e3471e79d692de4a54892c3d20fdd4b55e0:110172)
    at renderRoot (modules.js?hash=78a89e3471e79d692de4a54892c3d20fdd4b55e0:110203)
    at performWorkOnRoot (modules.js?hash=78a89e3471e79d692de4a54892c3d20fdd4b55e0:110778)
    at performWork (modules.js?hash=78a89e3471e79d692de4a54892c3d20fdd4b55e0:110699)

Is React-PivotTable Free to use like PivotTable?

Hi Nicolas,

I would like to know that likewise pivottable, is react-pivottble is free to use.

I'm bit confused as I've gone through plotly website and they have pricing structure also they have made the libraries open source as well. Please let me know is react-pivottable is fully free or first I've to buy plotly?

Thanks

UI dropdowns don't close when clicked

For example when changing the renderer or aggregator, they don't close until they are clicked twice. This behavior is present in the demo, is it intentional?

Editing plotly plots and callback

When editing is enabled for plotly plots, it is, for example, possible to edit the title of the plot. I'd like to use this feature, but how can I receive the new title through a callback to allow me to save the user input? As far as I can see, plotly has a callback onUpdate, but I do not know how to use it when the plotly plot is created through a PivotTableUI.

Default value for `aggregatorName`

Hi,
In your documentation, you write that the aggregatorName key should take as default value the first key in aggregators, but in the code (Utilities.js, line 777), the default value is Count.
This is annoying when defining custom aggregators, because the Count aggregator is not necessarily in the aggregator list, and you don't always want to specify a aggregatorName key, thus leading to an error.
So in my opinion, it would be better to have this default value as specified in the documentation :).

Many thanks,
Pierre

How to show only Table / Sum over a particular field.

This react pivot table perfectly does the job for me. However, at this moment I =only= need the Table renderer which sums the values of a particular field. So I don't want to show the selectors in the top left corner and want to set its default values on beforehand. How can I do this??

Allow passing config to Plotly

The Plotly renderers already allow passing layout options to Plotly through plotlyOptions, but there seems to be no way to pass Plotly config options. It would be nice if such config options could be passed in a similar way as layout options.

Customize filters

Hi,

I am implementing your project in my react application but I don't find the way to limit the filters available for my users.
For example I don't want them to use Table Heatmap, only Table, and the same for Sum and Sum over Sum.
Have you any tips I could use to resolve my problem?

By the way, it's an awesome project, congrats!
Regards

localization

Hi!
There is a documentation about localization in pivottable. It's for jquery. There is no posibility to manage locale in react-pivottable. It would be great if i could do it through some props.
Thanks.

Initial Roadmap

  • port over $.pivotUtilities and specs
  • basic TableRenderer
  • basic Storybook-powered website running at https://react-pivottable.js.org
  • basic PivotTable component
  • get eslint going and figure out a decent React formatting scheme
  • propTypes
  • basic dumb PivotTableUI component (just drag'n'drop and aggregator selection, no filter) plus smart wrapper (using https://github.com/RubaXa/Sortable ? )
  • filter menu on PivotTableUI MVP
  • pull together a ReadMe with a project charter
  • do a first NPM release to populate the entry a bit more
  • clean up PropType duplication
  • Plotly.js-react renderer!
  • Bar, column, line, plus stacked variants
  • GA on website
  • per-attribute sorters including in filter menu
  • order-preservation in unused area
  • hidden attributes, global and from drag/aggregator
  • row/col order UX
  • auto-rotation of unused when too long
  • fancier filter menu: select all/none
  • tear-away-able filter menus
  • menuLimit
  • come up with packaging strategy (think about polyfills?)
  • derived attributes
  • scatter charts
  • prop documentation in readme
  • Plotly renderer option passthrough
  • filter menu only button
  • Table heatmaps
  • stay-open reactive selects for renderer/aggregator ... click to close
  • Stacked area charts
  • new eslint and prettier, prePublish with new NPM?
  • renderers to mutate props via onChange? i.e. TableRenderer sorting UX finally
  • Convert aggregators to classes?
  • explore renderer-specific UI redraws: extra dropzones, settings dropdown etc
  • renderer options menu?
  • filter menu include mode
  • filter menu < > filters
  • Subtotals
  • localization, including smart number formatting
  • clean up decaffeination warts
  • get some badges, a CI setup for tests, some test coverage
  • Dash component (https://plot.ly/dash/plugins)
  • some React-level tests with jest
  • explore multiple aggregators

How do I re render the React Pivot UI using external button/drop down list etc ?

Thank you for the amazing library. I am new to react and I love the functionality React Pivot table offers!

I am trying to build a multi dataset pivot table using React Pivot Table. I am using a select tag to select a dataset and update the state. I am able to change the dataset before I start interacting with the pivotUI, once I drag row/column, I am unable to change the state thereafter. All I really want is to be able to select a dataset from the drop down menu and render the react pivot table with the new selected dataset.

I saw a similar issue for Jquery pivot table
nicolaskruchten/pivottable#736

Is there a overwrite prop for react pivot table or is there another workaround or am I doing it wrong?

Here's my code.

`import React from 'react';
import PivotTableUI from 'react-pivottable/PivotTableUI';
import 'react-pivottable/pivottable.css';
import TableRenderers from 'react-pivottable/TableRenderers';
import Plot from 'react-plotly.js';
import createPlotlyRenderers from 'react-pivottable/PlotlyRenderers';

// create Plotly renderers via dependency injection
const PlotlyRenderers = createPlotlyRenderers(Plot);

const data1 = [{'Country':'USA','Sales':45000},
{'Country':'USA','Sales':50000},{'Country':'CA','Sales':15000}]

const data2 = [{'Product':'Sofa','Sales':5000},{'Product':'Dinner
Table','Sales':50000},{'Product':'Chair','Sales':15000}]

const dataDic = {'Region':data1,'Products':data2}

class App extends React.Component {

constructor(props) {
super(props);
this.state = {selectedOption: 'Region'};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

handleChange(event) {
this.setState({selectedOption: event.target.value});

}

handleSubmit(event) {
alert('You have selected ' + this.state.selectedOption);
event.preventDefault();
}

render() {

return <div>
          <select defaultValue="Region" onChange={(e)=>   

this.handleChange(e)}>
Region
Products




          <PivotTableUI
              data={dataDic[this.state.selectedOption]}
              onChange={s => this.setState(s)}

       renderers={Object.assign({},TableRenderers)}//,PlotlyRenderers)}
              {...this.state}
          />

        </div>;
 }

}

export default App;`

Thanks
Yash Nigam

Export options

Hi, I'd like to be able to export the pivot table to CSV or Excel once the user is happy with the arrangement of a table. Do you have any tips for how to do this? I can't see anything built in to do this.

missing attrValues in DraggableAttribute

I get the following warning in the browser console (Linux Chrome, fwiw):
Warning: Failed prop type: The prop `attrValues` is marked as required in `DraggableAttribute`, but its value is `undefined`.
in DraggableAttribute (created by PivotTableUI)

However, there is no apparent unexpected behavior, as far as I can tell. This could be something wrong on my part, but I don't see anything related in the docs.

p.s. Thanks a million for this component! I was using the jQuery version, but on the whole find this more appealing for the real-time data discovery aspect... And glad to see Plotly supporting it.

Using this in R Shiny

Hello Nicholas,

This is Elijah and would like to know if this can be used within R Shiny? I'm new to coding and web dev but would certainly like to incorporate this or at least understand how it works in a viz web app. Thanks!

Trouble with PlotlyComponent Using External plotly.js

I'm using an external plotly.js version 1.15.0 with react-pivottable version 0.5.0.

The table views work fine, but I run into problems as soon as I try to create a chart.
I get an exception with an error message "Error while plotting: TypeError: Cannot read property 'selectAll' of undefined".

image

I get this error when plotComponentFactory() gets called. The PlotlyComponent.componentDidMount() function calls Plotly.newPlot and passes the container div element reference as a "div.js-plotly-plot" object. The error happens further down the line when plotly calls an "exports" function that expects this div object to have a ._fullLayout._infolayer.selectAll() function, but the ._infolayer property is missing from ._fullLayout.

Any ideas?

Large Dataset

Firstly, marvelous job on this Pivot table! I really like it. I have been trying to make a pivot table myself in react. And I have made a sample for a small data sample, however my main issue is how to render large data sets I am talking about thousands and yes possibly millions of data.
The pivoting algorithm is just fine, but the rendering time is just too much when we are talking about large data set. Lets say I have a CSV file of about 30MB and I am importing data from that file. The browser just can not handle data of this size, it just crashes!!
If you are going to make this pivot table in ReactJS, please tell me is there any way or some sort of idea to render data in amounts of thousands or millions in a pivot table??

"Stack" vs "Relative" barmode

Hi There,

First off, thanks for making and open-sourcing this library; it is proving very useful.

I wanted to propose a tiny code change to 2 lines in the instantiation of the plotly renderers in PlotlyRenderes.jsx. Specifically, I'm wondering if the layout options passed into the two stacked bar charts could specify { barmode: 'relative' } instead of { barmode: 'stack' }.

There may be reasons not to do it, which I'm not aware of, because I'm far from intimately familiar with plotly.js. However, the reason pro doing it is that currently, with { barmode: 'stack' }, if there are any negative values in the data, their bars end up overlapping and covering up other bars instead of sticking out on the negative side of the chart. In other words, as far as I can tell, when there are negative values, 'stack' mode results in a bug while 'relative' mode does what you'd expect. And I don't think there's a case where the opposite is true.

The only discussion I've found about this so far is this forum post in which someone points out this issue and Etienne addresses by creating the new { barmode: 'relative' }. However, no explanation is given as to why a new mode was needed instead of modifying the 'stack' mode.

Thanks for your consideration.

babel-standalone: ReferenceError: exports is not defined

Although Plotly React works properly in the browser with babel-standalone, React-pivottable throws
ReferenceError: exports is not defined:

image

Repro:

<!DOCTYPE html>
<html lang="en">

    <head>
        <title>Plotly/React/PivotTables in browser compilation</title>
        <script  src="https://unpkg.com/[email protected]/babel.js"></script>
        <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
        <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
        <script crossorigin src="https://cdn.plot.ly/plotly-latest.min.js"></script>
        <script crossorigin src="https://unpkg.com/[email protected]/dist/create-plotly-component.js"></script>
        <script crossorigin src="https://unpkg.com/[email protected]/PivotTableUI.js"></script>
    </head>

    <body>
        <div id="root-div"></div>

        <script type="text/babel">

            class App extends React.Component {
                render() {
                    return (
                        <div>
                            <Plot
                                data={[
                                {
                                    type: 'scatter',
                                    mode: 'lines+points',
                                    x: [1, 2, 3],
                                    y: [2, 6, 3],
                                    marker: {color: 'red'}
                                },
                                {
                                    type: 'bar',
                                    x: [1, 2, 3],
                                    y: [2, 5, 3]
                                }
                                ]}
                        
                                layout={{
                                width: 320,
                                height: 240
                                }}
                            />
                            </div>
                    );
                }
            }

            const Plot = createPlotlyComponent(Plotly);

            ReactDOM.render(
                <App/>,
                document.getElementById('root-div')
            );
        </script>
    </body>

</html>

Two or many values inside one aggregation

I have a scenario where I need to see the "Integer Sum" for two or more vals at the same time.

Reading how the default sum aggregator works, I see that's possible to return only one value on the function value(). So, for now I should be able to see only one value at once.

Is there any possibility to make it return multiple values by each aggregation?

Performance issue building from Github versus react-pivottable.js.org

Hi, guys.

I've noticed a huge difference in performance between the component deployed to https://react-pivottable.js.org/bundle.js in comparison to the bundle.js file that I've just build from the latest commit of master (aaff40f).

Do you know which commit is https://react-pivottable.js.org/bundle.js was built from?

Also, I tried using git bisect to explore this issue, but I'm not that experienced with bisect, and I actually got the impression that all commits from this github repository are slower in parsing CSV files than the one I linked above.

I'm uploading a sample CSV file, that loads instantaneously on https://react-pivottable.js.org, but freezes when I try the version from Github (stays forever, with CPU usage, in "Parsing CSV..." step)

Thank you for your time and assistance.

sample.csv.zip

[Feature request] Add support for specifying max-width of component

I'd like to fix this issue where the pivot table seems to be overflowing on the right of the app layout (using React Bootstrap and react 15.6.2). It seems the size of the component depends on the graph rendering. Is there a way to constraints this react component a bit more like scaling the graph rendering?

Thanks for your amazing work on this project btw. I really appreciate that.

screen shot 2017-12-06 at 11 08 50 am

Add click events to table or plot renderers

Hi, thanks for the great plugin, its working great, but I was wondering if there's a way to add click events to table fields or chart. Or some instructions on how to add them to renderers.

Thanks

I can't deploy the react component on apache server

Thanks for your attention!

I tried to deploy the react-pivottable component on apache server.
I installed the apache server and executed the react-pivottable app in my computer. Now I should deploy it on the apache server. So I tried to build the component to js file, but it doesn't work.
I have executed the following commands on the react-pivottable app.

$npm install #this is working
$npm start #this is working
$npm run build #this is not working
$npm run production #this is not working

My aim is to convert the component to general javascript file so that it is used to display some data on apache server.
I must use just the react component.
Please help me.

New Integration: react-pivottable or pivottable.js version?

I love this. Thank you.

We are trying to decide if it will address our users needs.

We're on a PHP, MySQL, Javascript (jQuery) platform.

  1. Should we go with react? or the regular javascript version?

  2. And, some tables from which users will run visualizations will have millions of rows. I am not sure if this is even conceivable/applicable to a pivot style table, but can pagination be added to control how many rows are viewed?

Thank you
Gilles

Is there a way to hook in remote queries?

Hi, I'm considering using this library, thanks for making it open source.

It seems like this library expects all the data to be loaded up-front and then thrown into the pivot table for pivoting. Because data can be a callback, it seems very easy to make remote calls to load data before users do the pivoting.

I'm working on a analytics UI with higher volume data that wont fit in the DOM. The data is stored in a star schema in a MPP database. Is there a way this library can work as a front-end query builder? Up front the product would provide the available facts/dimensions that can be selected, then the user would select fact(s) and dimension(s) with drag and drop, and hit "run". At I'd get called with the facts/dimensions the user has selected and could ping off to my remove server for the results.

I guess maybe what I'm looking for is more of an OLAP query builder vs. an in-memory pivot table. I just wanted to see if you had any thoughts on that, or had seem people with similar requests. I know this maybe be beyond the scope of the roadmap for this project, but the UIs for the solutions seem very similar.

Thanks again for making this project public, it's really slick.

How to remove the top and side part UI's ?

Hi Guys,

I want to know how can i silent the side parts of UI's means i had plotted a graph based on my data , now i want to only show the graph and for that i need to remove the UI's at the sides.

Is there any parameter for doing that ?

Thanks

Getting TypeError: this.props.aggregators[this.props.aggregatorName] when reloading the PivotUI ?

Hi

Here is my code

import React, { Component } from 'react';
import tips from './tips';
import PivotTableUI from 'react-pivottable/PivotTableUI';
import 'react-pivottable/pivottable.css';
import TableRenderers from 'react-pivottable/TableRenderers';
import Plot from 'react-plotly.js';
import createPlotlyRenderers from 'react-pivottable/PlotlyRenderers';

const PlotlyRenderers = createPlotlyRenderers(Plot);

function isDiff(a,b) {
  return JSON.stringify(a) !== JSON.stringify(b);
}
class App extends Component {
  state = {
    pivotState5: {
      data:  [["Name", "CreationDate"]],
      rows: ['Name'],
      cols: ['Humanize'],
      aggregatorName: 'Count',
      rendererName: 'Grouped Column Chart'
      }
  };

 handleClick = () => {
                this.setState(
                  {
                    pivotState5: {
                      data: tips,
                      rows: ['Payer Gender'],
                      cols: ['Party Size'],
                      aggregatorName: 'Count',
                      rendererName: 'Grouped Column Chart'                  
                    } 
                  }
                  );
                  
        }
        
        componentDidMount() {
          let state = JSON.parse(localStorage.getItem('pivotState5'));
          this.setState(state);
          console.log(this.state);
          console.log("inside didmount");
        }
        
        
        componentDidUpdate(prevProps, prevState) {
        
          if (isDiff(this.state, prevState)) {
            localStorage.setItem('pivotState5', JSON.stringify(this.state));
            console.log(this.state);
            console.log("inside didupdate");
            // localStorage.clear();
            // console.log("localstorage cleared");
          }
        
        }
      
render() {
  //console.log(this.state)
  return (
    <div styles="width=50px">
      <PivotTableUI
               //  data={this.state.pullResults.body || []}
                onChange={s => this.setState({pivotState5: s})}
                renderers={Object.assign({}, TableRenderers, PlotlyRenderers)}
                {...this.state.pivotState5}
            />
            
            
      <button onClick={this.handleClick}>Get results</button>
    </div>

  );
  }
}

export default App;

Here is my tips.js

export default [
    ["Total Bill","Tip","Payer Gender","Payer Smoker","Day of Week","Meal","Party Size"],
    [16.99,1.01,"Athelete","Non-Smoker","Sunday","Dinner",2]
    ];

I am getting error like this

TypeError: this.props.aggregators[this.props.aggregatorName] is not a function

And both the states like the state from the database is identical to the one that I had before reloading the app .

I already check this https://github.com/plotly/react-pivottable/issues/20 issue.

In that question he said he is saving the attributes

['data', 'rows', 'cols', 'aggregatorName', 'vals', 'rendererName', 'sorters', 'plotlyOptions']

I am too doing the same thing in the state. But getting the same error. Usually aggregators takes key which is aggregatorName that I am providing.

Any help is appreciated

Thanks

Resizing plot area?

I'm using this component in Vue thanks Vuera, a vue package that lets me use React components within Vue. This is working fine, except for plots. I can't find a way to resize plots. With CSS, table views automatically resize to width in %, but plots don't seem to.

I've tried everything from the plotlyOptions object to Plotly.Plots.resize()

The plotlyOptions object works the first time: if I pass this as a prop, plotly receives it and draws a chart in the specified size), but if I change the value of plotlyOptions.width nothing happens (the property is reactive, as changing the data object works fine)

Table freezes with ~5,000 entries

Hi,

I'm fetching an array consisting of around 5,000 objects. As soon as I drag in a second field the entire table freezes and the page continues to hang indefinitely. Is there any way for me to handle this volume of data in pivottable?

I've tried the following by slicing the array

  • 1,000 rows, snappy
  • 2,000 rows, slight delay
  • 3,000 rows, increased delay
  • 4,000 rows, major delay
  • 5,000 rows, complete freeze

I've also tried only pulling 3 properties off of each object, reducing the array. This unfortunately had no effect.

pivot filter box position

Hi,

Awesome work!

Recently in my project, I found that pivot filter box will be out of view port. Line 214, inn the file PivotTableUI.js, I saw the position is the absolute distance. However, seems that react-draggable is using relative distance from parent dom (Not sure, though)

option to show only table/chart

This is a feature request/suggestion: to hide all pivottable controls, keeping only the pivot table/chart, similar to in Excel. This would be simply a boolean API key with a default value of true.

I am trying to not only explore data, but also save charts for later use in a dashboard, in which case there would be no changing of aggregators, etc., yet the data would still automatically update (somewhat like in Metabase). However, the pivot functionality is still needed, even if the controls are disabled. Other options to achieve this are 1) my own CSS (which I'll do in the short term) and 2) server-side replication of the pivottable functionality to serve the pivoted data.

newPlot of undefined error when used with external plotly.js ?

HI,

Steps to reproduce

Here is my npm install command npm install --save react-pivottable react-plotly.js react react-dom

Here is my App.js file

import React, { Component } from 'react';
import tips from './tips';
import PivotTable from 'react-pivottable/PivotTable';
import 'react-pivottable/pivottable.css';
import TableRenderers from 'react-pivottable/TableRenderers';
import createPlotlyComponent from 'react-plotly.js/factory';
import createPlotlyRenderers from 'react-pivottable/PlotlyRenderers';
import AWS from 'aws-sdk';
// create Plotly React component via dependency injection
const Plot = createPlotlyComponent(window.Plotly);

// create Plotly renderers via dependency injection
const PlotlyRenderers = createPlotlyRenderers(Plot);

class App extends Component {
  state = {
    filename: 'Sample Dataset: Tips',
    pivotState: {
      data:  [["Name", "CreationDate"]],
      rows: ['Name'],
      cols: ['Humanize'],
      aggregatorName: 'Count',
      rendererName: 'Grouped Column Chart',
  plotlyOptions: {width: 500, height: 500}
  }
  };

 handleClick = () => {
                this.setState(
                  {
                    filename: 'Sample Dataset: Tips',
                    pivotState: {
                      data: tips,
                      rows: ['Payer Gender'],
                      cols: ['Party Size'],
                      aggregatorName: 'Count',
                      rendererName: 'Grouped Column Chart',
                  plotlyOptions: {width: 600, height: 500}
                  }
                  });
        }
render() {
    //console.log(this.state)
  return (
    <div styles="width=50px">
      <PivotTable
               //  data={this.state.pullResults.body || []}
                onChange={s => this.setState({pivotState: s})}
                renderers={Object.assign({}, TableRenderers, PlotlyRenderers)}
                {...this.state.pivotState}
            />
            
      <button onClick={this.handleClick}>Get results</button>
    </div>

  );
  }
}


export default App;

My tips component is like this

export default [
    ["Total Bill","Tip","Payer Gender","Payer Smoker","Day of Week","Meal","Party Size"],
    [16.99,1.01,"Female","Non-Smoker","Sunday","Dinner",2],
    [10.34,1.66,"Male","Non-Smoker","Sunday","Dinner",3],
    [21.01,3.5,"Male","Non-Smoker","Sunday","Dinner",3] ];

When rendering i am getting error like this

Error while plotting: TypeError: Cannot read property 'newPlot' of undefined

But when i installed plotly.js and used the import stmts that presented in documentation and modified as above it worked correctly but not working fine without plotly.js

Am i missing anything ?

Any help is appreciated

Thanks

remember open/closed state of filters (feature suggestion)

The title says it all: It would be nice to have a prop in PivotTableUI indicating the open/closed state of specific filters, including, possibly, their location. Something like valueFilterState, with attributes as keys and objects indicating open/closed/position state as values. Following react-draggable's Controlled vs. Uncontrolled discussion this could look something like: {[attribute]: {open: true, position: {x: number, y: number}}}. Then I guess onDrag and onStop would be added from PivotTableUI props as onDrag: (fromReactDraggable) => props.onDrag({attribute, ...fromReactDraggable}).

unable to define a custom aggregator with custom formatter

Hello All,

I am defining aggregator like this .

SumResidual: () => aggregatorTemplates.Sum(CustomFormatter)([aggregateFieldName]),

and aggregatorName=SumResidual

also I am defining vals to aggregateFieldName

  1. CustomFormatter is my own formatter function
  2. aggregatorFieldName is of string array and is the value of field on which aggregation needs to be performed

But the below line in Utilities.js
this.aggregator = this.props.aggregatorsthis.props.aggregatorName;

calls sum()() with _ref3 as my formatter function where I am expecting it should receive the aggreagtor field name

below is the sum function from utilities.
sum: function sum() {
var formatter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : usFmt;

return function (_ref3) {
  var _ref4 = _slicedToArray(_ref3, 1),
      attr = _ref4[0];

  return function () {
    return {
      sum: 0,
      push: function push(record) {
        if (!isNaN(parseFloat(record[attr]))) {
          this.sum += parseFloat(record[attr]);
        }
      },
      value: function value() {
        return this.sum;
      },

      format: formatter,
      numInputs: typeof attr !== 'undefined' ? 0 : 1
    };
  };
};

},

Am I doing it correctly ?

Any help is appreciated :)

Regards

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.