React-based drag'n'drop pivot table with Plotly.js charts

Overview

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

Comments
  • update deprecated lifecycle methods

    update deprecated lifecycle methods

    Super naive approach - I basically switched componentWillMount to componentDidMount and componentWillUpdate to componentDidUpdate. componentDidUpdate receives prevProps instead of nextProps, so I also changed this.materializeInput(nextProps.data) to this.materializeInput(this.props.data).

    npm run test:jest passes, but npm run test fails at the prettier stage.

    FWIW there's still a componentWillMount and a componentWillUpdate in examples/App.jsx but I didn't want to muck with that...

    opened by tarekrached 11
  • Table freezes with ~5,000 entries

    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.

    opened by mitchhankins01 11
  • pivot filter box position

    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)

    opened by CraigMeng 11
  • Status of this project?

    Status of this project?

    Hey Plotly folks! This is an amazing project, thank you so much for releasing it!

    I'm curious about your plans for this repo - as of today, February 10, it's been 8 months since the last commit (c9b6ab66786cf0e6ccf382fb2576d8e1c1434e4d Create FUNDING.yml) and over 15 months since the last substantive commit (e708ab45a53496c138dc646163ae9e10647a3155 on Nov 3, 2018).

    In its current state, react-pivottable generates componentWillMount and componentWillUpdate warnings when used with current (16.x) React, and will probably not work with React 17.x when that drops.

    There are three open dependabot PRs that are 4 months old at this point, which makes me wonder if the project owner is looking at the project.

    I guess what I'm asking is: is this project abandoned? What can we do to support it? If I invest time in PRs to address the React warnings, are there folks at Plotly who will review them?

    Thanks again - I do not take any of the work in this repo for granted, and really do appreciate what you have built. I would love to see it flourish.

    opened by tarekrached 8
  • "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.

    opened by meetamit 7
  • Drag and drop fields from one axis to another will duplicate them in React 18

    Drag and drop fields from one axis to another will duplicate them in React 18

    https://user-images.githubusercontent.com/6526498/176625436-4b45ccd1-6a76-4efb-a1d7-00e30c344ade.mov

    We are willing to send a PR to fix this, as we are heavy users of this library at IMC. It's likely a bug with an older version of react-sortablejs or react-draggable.

    Would anyone be able to review it? Haven't seen anyone responding to issues lately.

    opened by ianldgs 6
  • How do I define my own color scheme for Table Heatmap?

    How do I define my own color scheme for Table Heatmap?

    Hi,

    I would like to use custom color scales in Table Heatmap, just like the Montreal Weather 2014 Dataset example for pivottable.js. How do I do this in react-pivottable?

    opened by deecay 6
  • How to make some default views?

    How to make some default views?

    i want to make some defaults as preset.

    so user can click a link and check this view directly without dragging by themself.

    like this

    https://jsfiddle.net/nicolaskruchten/kn381h7s/

    opened by crapthings 6
  • Expose aggregator outlet to allow rendering additional content in aggregatorCell

    Expose aggregator outlet to allow rendering additional content in aggregatorCell

    This PR introduces an additional key on aggregators, outlet, a function which, if present, gets called once by PivotTableUI to render additional aggregator-specific content just below the built-in aggregator selector (in the area outlined in red here):

    Screen Shot 2020-10-19 at 11 50 34 AM

    Some use cases for providing this escape hatch include:

    • rendering aggregator-specific custom UI controls
    • rendering aggregate stats that you want visible regardless of the state of the pivottable attributes

    When the outlet function is called, it will be passed the PivotTableUI's props.data, in case the called aggregator wants to make use of that data.

    Here's a kind of silly example of a custom aggregator using this new function:

      function customCount(formatter) {
        return () => 
          function() {
            return {
              count: 0,
              push() {
                this.count++;
              },
              value() {
                return this.count;
              },
              format: formatter,
              outlet: (records) => {
                return (
                  <div>There are ${records.length} records total</div>
                );
              },
            };
          };
        };
      },
    

    Resolves #117

    opened by nselikoff 5
  • newPlot of undefined error when used with external plotly.js ?

    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

    opened by Private-SO 5
  • [Feature request] Add support for specifying max-width of component

    [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
    opened by richerlariviere-lightspeed 5
  • Adding other plotly charts types

    Adding other plotly charts types

    Is it possible to add other types of charts to the dropdown list? I need to add radar chart and support for the map (plotly.js relay on MapBox for the map visualization)

    Is it something I can do in the configurations or I need to make changes to the source code?

    opened by MarcoGiorgi 0
  • Adding link to values

    Adding link to values

    I want to add link to specific column to my array. My json array is [ { "TaskID": "161114683317", "Client": "Test" }, { "TaskID": "161114683317", "Client": "Test" } ]

    If I try adding a tag while creating array like this: "TaskID": "<a href='http://localhost:3000/task_details/NDM0NzY='>161114683317</a>"

    it doesn't render html this print as it received from response.

    This is my config for pivot const pivotPresets = { rendererName, aggregatorName, plotlyOptions: {width: 900, height: 500}, plotlyConfig: {}, rendererOptions: { } } And UI <PivotTableUI data={data} onChange={(s) => { setPivotTableUIConfig(s) setdata(s) }} unusedOrientationCutoff={Infinity} {...pivotPresets} renderers={Object.assign({}, TableRenderers, PlotlyRenderers)} {...pivotTableUIConfig} />

    Please help what I am missing in this.

    opened by dividedbyzero323 0
  • Access Result data / Export Result Data to json format

    Access Result data / Export Result Data to json format

    Hi Team,

    we want to convert the table generated by Pivot Table into Json Structure and want to save that data in the server.

    Can you please guide , how we can access the result/output data or convert the output data into json form .

    Regards, Akash

    opened by akash-goel 0
Releases(v0.11.0)
Customizable React-based editor panel for Plotly charts

Customizable React-based editor panel for Plotly charts

Plotly 443 Jan 1, 2023
A thin, typed, React wrapper over Google Charts Visualization and Charts API.

React Google Charts A thin, typed, React wrapper for Google Charts. Docs and examples. React Google Charts Docs and examples. Installation Quick Start

Rakan Nimer 1.4k Jan 4, 2023
A thin, typed, React wrapper over Google Charts Visualization and Charts API.

A thin, typed, React wrapper for Google Charts. Docs and examples. React Google Charts Docs and examples. Installation Quick Start

Rakan Nimer 1.4k Jan 6, 2023
A React library for creating animated charts visualizations based on dynamic data.

react-dynamic-charts (demo) A React library for creating animated charts visualizations based on dynamic data. Install npm install --save react-dynami

Daniel Sternlicht 214 Nov 18, 2022
Highly customizable library for building interactive node-based UIs, editors, flow charts and diagrams

React Flow is a library for building node-based graphs. You can easily implement custom node types and it comes with components like a mini-map and graph controls.

webkid 13.2k Jan 4, 2023
React minimal pie chart🍰 Lightweight but versatile SVG pie/donut charts for React. < 2kB gzipped.

React minimal pie chart Lightweight React SVG pie charts, with versatile options and CSS animation included. < 2kB gzipped. ?? Demo ?? . Why? Because

Andrea Carraro 341 Dec 14, 2022
πŸ“Š πŸ“ˆ πŸ“‰ React.js plugin for building charts using CSS

Chartify React.js plugin for building charts using CSS. Demo The source for this module is in the main repo. Example app is here. Backend service for

Kirill Stepkin 685 Jan 1, 2023
πŸ“Š πŸ“ˆ πŸ“‰ React.js plugin for building charts using CSS

Chartify React.js plugin for building charts using CSS. Demo The source for this module is in the main repo. Example app is here. Backend service for

Kirill Stepkin 685 Jan 1, 2023
React components for building composable and flexible charts

rumble-charts React components for building composable and flexible charts to visualize your data. It's based on D3.js under the hood, but most of the

null 338 Dec 26, 2022
Modular React charts made with d3.js

Update Important update: The actively maintained fork of this project is now at the Github of react-d3 co-creator yang-wei, who has recently taken the

Eric S. Bullington 1.8k Oct 27, 2022
react d3 charts

CRA-MHL A Professional Starter Create React App (CRA) with Must-Have Libraries (MHL) Template A very opinionated starter Create React App (CRA) templa

Oscar Cardoso Garcia 6 Oct 19, 2022
Reactochart is a library of React components for creating data visualization charts and graphs.

Reactochart is a library of React components for creating data visualization charts and graphs. Components include line chart, bar chart, area chart, heat maps, scatterplot, histogram, pie chart, sankey diagram, and tree map.

Spotify 530 Dec 26, 2022
βš›οΈ Simple, immersive & interactive charts for React

βš›οΈ Simple, immersive & interactive charts for React

Tanner Linsley 2.3k Jan 6, 2023
React wrapper for Smoothie Charts

react-smoothie React wrapper for Smoothie Charts. Install With Yarn: yarn add react-smoothie With NPM: npm install react-smoothie --save Install from

Cameron Tacklind 43 Nov 15, 2021
βš›οΈ Simple, immersive & interactive charts for React

Simple, immersive and interactive charts for React Enjoy this library? Try the entire TanStack! React Table, React Query, React Form Visit react-chart

Tanner Linsley 2.3k Jan 4, 2023
A collection of easy to use charts created in D3 for your React applications.

react-charts-d3 A collection of easy to use charts created in D3 for your React applications. Area Chart Bar Chart Bubble Chart Line Chart Pie Chart S

Nick Turner 4 Jan 19, 2021
Plug and play React charts

Orama [DEPRECATED] This package has been deprecated as it is no longer used by Kensho internally and we do not plan to continue maintaining it. We hop

Kensho 124 Nov 12, 2022
Create beautiful JavaScript charts with one line of React

React Chartkick Create beautiful JavaScript charts with one line of React See it in action Supports Chart.js, Google Charts, and Highcharts Quick Star

Andrew Kane 1.2k Dec 28, 2022
Bar, Line, Area, Pie, and Donut charts in React Native

react-native-gifted-charts The most complete library for Bar, Line, Area, Pie, and Donut charts in React Native. Allows 2D, 3D, gradient, animations a

Abhinandan Kushwaha 208 Dec 28, 2022