Skip to content

Instantly share code, notes, and snippets.

@paulperry
Created June 2, 2016 15:39
Show Gist options
  • Save paulperry/ee592a37e644d732578d6ba3e9e04279 to your computer and use it in GitHub Desktop.
Save paulperry/ee592a37e644d732578d6ba3e9e04279 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# DeclarativeWidgets DataFrame Sync Test 2"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from IPython.core.display import HTML, display, clear_output\n",
"import pandas as pd\n",
"# pd.show_versions()\n",
"\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 46,
"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": 47,
"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": 63,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def print_df(idx:int):\n",
" global df1, df2, df3\n",
" clear_output()\n",
" print(idx)\n",
" if idx > 1:\n",
" display(df3.style.set_properties(subset=['f'], **{'background-color': 'pink'}))\n",
" else:\n",
" display(df2.style.set_properties(subset=['c'], **{'background-color': 'pink'}))"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<template is=\"urth-core-bind\">\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"
}
],
"source": [
"%%html\n",
"<template is=\"urth-core-bind\">\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": 66,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n"
]
},
{
"data": {
"text/html": [
"\n",
" <style type=\"text/css\" >\n",
" \n",
" \n",
" #T_dbaab18a_28d7_11e6_a50b_0242ac110002row0_col1 {\n",
" \n",
" background-color: pink;\n",
" \n",
" }\n",
" \n",
" #T_dbaab18a_28d7_11e6_a50b_0242ac110002row1_col1 {\n",
" \n",
" background-color: pink;\n",
" \n",
" }\n",
" \n",
" </style>\n",
"\n",
" <table id=\"T_dbaab18a_28d7_11e6_a50b_0242ac110002\" None>\n",
" \n",
"\n",
" <thead>\n",
" \n",
" <tr>\n",
" \n",
" <th class=\"blank\">\n",
" \n",
" <th class=\"col_heading level0 col0\">e\n",
" \n",
" <th class=\"col_heading level0 col1\">f\n",
" \n",
" </tr>\n",
" \n",
" </thead>\n",
" <tbody>\n",
" \n",
" <tr>\n",
" \n",
" <th id=\"T_dbaab18a_28d7_11e6_a50b_0242ac110002\" class=\"row_heading level1 row0\">\n",
" \n",
" 0\n",
" \n",
" \n",
" <td id=\"T_dbaab18a_28d7_11e6_a50b_0242ac110002row0_col0\" class=\"data row0 col0\">\n",
" \n",
" 9\n",
" \n",
" \n",
" <td id=\"T_dbaab18a_28d7_11e6_a50b_0242ac110002row0_col1\" class=\"data row0 col1\">\n",
" \n",
" 10\n",
" \n",
" \n",
" </tr>\n",
" \n",
" <tr>\n",
" \n",
" <th id=\"T_dbaab18a_28d7_11e6_a50b_0242ac110002\" class=\"row_heading level1 row1\">\n",
" \n",
" 1\n",
" \n",
" \n",
" <td id=\"T_dbaab18a_28d7_11e6_a50b_0242ac110002row1_col0\" class=\"data row1 col0\">\n",
" \n",
" 11\n",
" \n",
" \n",
" <td id=\"T_dbaab18a_28d7_11e6_a50b_0242ac110002row1_col1\" class=\"data row1 col1\">\n",
" \n",
" 12\n",
" \n",
" \n",
" </tr>\n",
" \n",
" </tbody>\n",
" </table>\n",
" "
],
"text/plain": [
"<pandas.core.style.Styler at 0x7f4636e57278>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%html\n",
"<template is=\"urth-core-bind\">\n",
" <template is=\"dom-if\" if=\"{{sel1}}\" auto>\n",
" <urth-core-function ref=\"print_df\" arg-idx=\"[[sel1.0]]\" result=\"{{df_out}}\" auto>\n",
" </urth-core-function>\n",
" </template>\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