Skip to content
This repository was archived by the owner on Jun 22, 2019. It is now read-only.

Commit 4443859

Browse files
committed
experiment with row renderers, enabled by plotly/dash-renderer#26
1 parent 56a4ecd commit 4443859

File tree

4 files changed

+88
-3
lines changed

4 files changed

+88
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"copy-lib": "cp lib/* dash_table_experiments",
1717
"demo": "builder run demo",
1818
"install-local": "npm run copy-lib && python setup.py install",
19-
"prepublish": "npm test && builder run build-dist && npm run copy-lib",
19+
"prepublish": "builder run lint && builder run build-dist && npm run copy-lib",
2020
"build-local": "builder run build-dist && npm run copy-lib",
2121
"publish-all": "npm publish && python setup.py sdist upload",
2222
"publish-pypi": "npm run prepublish && python setup.py sdist upload",

src/components/DataTable.react.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {Component, PropTypes} from 'react';
2-
import ReactDataGrid from 'react-data-grid';
2+
import ReactDataGrid, {Row} from 'react-data-grid';
33
import {Toolbar} from 'react-data-grid-addons';
44
import R from 'ramda';
55

@@ -87,7 +87,16 @@ class DataTable extends Component {
8787
name: c,
8888
editable: Boolean(props.editable),
8989
sortable: Boolean(props.sortable),
90-
filterable: Boolean(props.filterable)
90+
filterable: Boolean(props.filterable),
91+
formatter: cellProps => {
92+
/* eslint-disable */
93+
console.warn(cellProps);
94+
/* eslint-enable */
95+
return (R.type(cellProps.value) === 'Object' ?
96+
props.render(cellProps.value) :
97+
<div>{cellProps.value}</div>
98+
);
99+
}
91100
}));
92101

93102
this.setState(newState);
@@ -302,6 +311,14 @@ class DataTable extends Component {
302311
rowGetter={this.rowGetter}
303312
rowsCount={this.getSize()}
304313

314+
rowRenderer={props => {
315+
/* eslint-disable */
316+
console.warn(props);
317+
/* eslint-enable */
318+
props.height = props.idx === 0 ? 100 : props.height;
319+
return (<Row {...props}/>);
320+
}}
321+
305322
{...extraProps}
306323

307324
/>

usage-sparklines.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# -*- coding: UTF-8 -*-
2+
3+
import dash
4+
from dash.dependencies import Input, Output, State
5+
import dash_core_components as dcc
6+
import dash_html_components as html
7+
import dash_table_experiments as dt
8+
import json
9+
import pandas as pd
10+
import plotly
11+
12+
app = dash.Dash()
13+
14+
app.scripts.config.serve_locally = True
15+
16+
DF_GAPMINDER = pd.read_csv(
17+
'https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv'
18+
)
19+
sparklines = {
20+
c: html.Div(style={'height': 100, 'width': '100%'}, children=dcc.Graph(
21+
id=c,
22+
figure={
23+
'data': [{
24+
'x': DF_GAPMINDER[c],
25+
'type': 'histogram'
26+
}],
27+
'layout': {
28+
'height': 100,
29+
'width': 150,
30+
'margin': {
31+
'l': 0, 'r': 0, 't': 0, 'b': 0
32+
},
33+
'xaxis': {
34+
'showticklabels': False,
35+
'showline': False,
36+
'showgrid': False,
37+
},
38+
'yaxis': {
39+
'showticklabels': False,
40+
'showline': False,
41+
'showgrid': False,
42+
}
43+
}
44+
},
45+
config={'displayModeBar': False}
46+
))
47+
for c in DF_GAPMINDER.columns
48+
}
49+
50+
app.layout = html.Div([
51+
html.H1('💖 Dash Sparklines 💖', style={'textAlign': 'center'}),
52+
html.H2(html.I('Coming Soon'), style={'textAlign': 'center'}),
53+
dt.DataTable(
54+
rows=[sparklines] + DF_GAPMINDER.to_dict('records'),
55+
id='table',
56+
min_height=1500,
57+
),
58+
html.Div(dcc.Dropdown(), style={'display': 'none'})
59+
], className="container")
60+
61+
62+
app.css.append_css({
63+
"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"
64+
})
65+
66+
if __name__ == '__main__':
67+
app.run_server(debug=True, port=8060)

usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import plotly
1010

1111
app = dash.Dash()
12+
server = app.server
1213

1314
app.scripts.config.serve_locally = True
1415
# app.css.config.serve_locally = True

0 commit comments

Comments
 (0)