Created
May 19, 2016 20:53
-
-
Save paulperry/8d592aefc09948b21b9e7b317f235710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# DeclarativeWidgets DataFrame Sync Test" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"INSTALLED VERSIONS\n", | |
"------------------\n", | |
"commit: None\n", | |
"python: 3.5.1.final.0\n", | |
"python-bits: 64\n", | |
"OS: Linux\n", | |
"OS-release: 4.4.8-boot2docker\n", | |
"machine: x86_64\n", | |
"processor: \n", | |
"byteorder: little\n", | |
"LC_ALL: en_US.UTF-8\n", | |
"LANG: en_US.UTF-8\n", | |
"\n", | |
"pandas: 0.17.1\n", | |
"nose: None\n", | |
"pip: 8.1.1\n", | |
"setuptools: 20.3\n", | |
"Cython: None\n", | |
"numpy: 1.10.4\n", | |
"scipy: 0.17.0\n", | |
"statsmodels: None\n", | |
"IPython: 4.1.2\n", | |
"sphinx: None\n", | |
"patsy: None\n", | |
"dateutil: 2.5.0\n", | |
"pytz: 2016.1\n", | |
"blosc: None\n", | |
"bottleneck: None\n", | |
"tables: None\n", | |
"numexpr: None\n", | |
"matplotlib: 1.5.1\n", | |
"openpyxl: None\n", | |
"xlrd: None\n", | |
"xlwt: None\n", | |
"xlsxwriter: None\n", | |
"lxml: None\n", | |
"bs4: None\n", | |
"html5lib: None\n", | |
"httplib2: None\n", | |
"apiclient: None\n", | |
"sqlalchemy: None\n", | |
"pymysql: None\n", | |
"psycopg2: None\n", | |
"Jinja2: None\n" | |
] | |
} | |
], | |
"source": [ | |
"from IPython.core.display import HTML\n", | |
"import pandas as pd\n", | |
"pd.show_versions()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<link rel=\"import\" href=\"urth_components/urth-viz-table/urth-viz-table.html\" is=\"urth-core-import\">" | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%%html\n", | |
"<link rel=\"import\" href=\"urth_components/urth-viz-table/urth-viz-table.html\" is=\"urth-core-import\">" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"df1 = pd.DataFrame([[1,2],[3,4]], columns=['a','b'])\n", | |
"df1.columns.name = 'df1'\n", | |
"df2 = pd.DataFrame([[5,6],[7,8]], columns=['c','d'])\n", | |
"df2.columns.name = 'df2'\n", | |
"df3 = pd.DataFrame([[9,10],[11,12]], columns=['e','f'])\n", | |
"df3.columns.name = 'df3'\n", | |
"df2_orig = df2.copy()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th>df1</th>\n", | |
" <th>a</th>\n", | |
" <th>b</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>1</td>\n", | |
" <td>2</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>3</td>\n", | |
" <td>4</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
"df1 a b\n", | |
"0 1 2\n", | |
"1 3 4" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"df1" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th>df2</th>\n", | |
" <th>c</th>\n", | |
" <th>d</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>5</td>\n", | |
" <td>6</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>7</td>\n", | |
" <td>8</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
"df2 c d\n", | |
"0 5 6\n", | |
"1 7 8" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"df2" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th>df3</th>\n", | |
" <th>e</th>\n", | |
" <th>f</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>9</td>\n", | |
" <td>10</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>11</td>\n", | |
" <td>12</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
"df3 e f\n", | |
"0 9 10\n", | |
"1 11 12" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"df3" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# this doesn't work: the change to df1 is not reflected in the viz-table immediately\n", | |
"def get_row(idx:int):\n", | |
" print(idx)\n", | |
" global df1, df2\n", | |
" if idx > 1:\n", | |
" print('swap')\n", | |
" df2 = df3\n", | |
" else:\n", | |
" df2 = df2_orig\n", | |
" return idx" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<template is=\"dom-bind\">\n", | |
" <urth-core-function ref=\"get_row\" arg-idx=\"[[sel1.0]]\" result=\"{{res}}\" auto>\n", | |
" </urth-core-function>\n", | |
" <urth-core-dataframe id='df1' ref=\"df1\" value=\"{{df1}}\" auto></urth-core-dataframe>\n", | |
" <urth-viz-table datarows=\"{{df1.data}}\" columns=\"{{df1.columns}}\" selection=\"{{sel1}}\" rows-visible=6>\n", | |
" </urth-viz-table>\n", | |
"</template>" | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"3\n", | |
"swap\n" | |
] | |
} | |
], | |
"source": [ | |
"%%html\n", | |
"<template is=\"dom-bind\">\n", | |
" <urth-core-function ref=\"get_row\" arg-idx=\"[[sel1.0]]\" result=\"{{res}}\" auto>\n", | |
" </urth-core-function>\n", | |
" <urth-core-dataframe id='df1' ref=\"df1\" value=\"{{df1}}\" auto></urth-core-dataframe>\n", | |
" <urth-viz-table datarows=\"{{df1.data}}\" columns=\"{{df1.columns}}\" selection=\"{{sel1}}\" rows-visible=6>\n", | |
" </urth-viz-table>\n", | |
"</template>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false, | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<template is=\"dom-bind\">\n", | |
" <urth-core-dataframe id='df2' ref=\"df2\" value=\"{{df2}}\" auto></urth-core-dataframe>\n", | |
" <urth-viz-table datarows=\"{{df2.data}}\" columns=\"{{df2.columns}}\" selection=\"{{sel2}}\" rows-visible=6>\n", | |
" </urth-viz-table>\n", | |
"</template>" | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%%html\n", | |
"<template is=\"dom-bind\">\n", | |
" <urth-core-dataframe id='df2' ref=\"df2\" value=\"{{df2}}\" auto></urth-core-dataframe>\n", | |
" <urth-viz-table datarows=\"{{df2.data}}\" columns=\"{{df2.columns}}\" selection=\"{{sel2}}\" rows-visible=6>\n", | |
" </urth-viz-table>\n", | |
"</template>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## now, select the second row of the first table above (df1)\n", | |
"\n", | |
"we expect the table to change to df2, but it doesn't" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": false, | |
"scrolled": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th>df3</th>\n", | |
" <th>e</th>\n", | |
" <th>f</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>9</td>\n", | |
" <td>10</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>11</td>\n", | |
" <td>12</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
"df3 e f\n", | |
"0 9 10\n", | |
"1 11 12" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# printing df2 now somehow makes the change in the viz-table above\n", | |
"df2" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### a refresh button works" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<template is=\"dom-bind\">\n", | |
" <urth-core-function ref=\"get_row\" arg-idx=\"[[sel1.0]]\" result=\"{{res}}\" auto>\n", | |
" </urth-core-function>\n", | |
" <urth-core-dataframe id='df1' ref=\"df1\" value=\"{{df1}}\" auto></urth-core-dataframe>\n", | |
" <urth-viz-table datarows=\"{{df1.data}}\" columns=\"{{df1.columns}}\" selection=\"{{sel1}}\" rows-visible=6>\n", | |
" </urth-viz-table>\n", | |
" <button onClick=\"$('#df2').get(0).refresh()\">refresh</button>\n", | |
"</template>" | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%%html\n", | |
"<template is=\"dom-bind\">\n", | |
" <urth-core-function ref=\"get_row\" arg-idx=\"[[sel1.0]]\" result=\"{{res}}\" auto>\n", | |
" </urth-core-function>\n", | |
" <urth-core-dataframe id='df1' ref=\"df1\" value=\"{{df1}}\" auto></urth-core-dataframe>\n", | |
" <urth-viz-table datarows=\"{{df1.data}}\" columns=\"{{df1.columns}}\" selection=\"{{sel1}}\" rows-visible=6>\n", | |
" </urth-viz-table>\n", | |
" <button onClick=\"$('#df2').get(0).refresh()\">refresh</button>\n", | |
"</template>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment