Skip to content

Instantly share code, notes, and snippets.

@paulperry
Created May 19, 2016 03:31
Show Gist options
  • Save paulperry/22c05e9098cacd5eaa6f78e34efc2b39 to your computer and use it in GitHub Desktop.
Save paulperry/22c05e9098cacd5eaa6f78e34efc2b39 to your computer and use it in GitHub Desktop.
Trying to get cell position from a declarativewidgets urth-viz-table : https://github.com/jupyter-incubator/declarativewidgets/issues/364
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 17,
"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": [
"pd.show_versions()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"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": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'urth.widgets' has no attribute 'init'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-26-dfcfa652665f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0murth\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mwidgets\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mwidgets\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m: module 'urth.widgets' has no attribute 'init'"
]
}
],
"source": [
"from urth import widgets\n",
"\n",
"widgets.init()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df = pd.DataFrame([\n",
" [\"A\", 1],\n",
" [\"B\", 2]\n",
" ], columns=[\"Letter\", \"Number\"]\n",
")"
]
},
{
"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></th>\n",
" <th>Letter</th>\n",
" <th>Number</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>A</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>B</td>\n",
" <td>2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Letter Number\n",
"0 A 1\n",
"1 B 2"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def get_cell(cell:str):\n",
" print(cell)\n",
" return cell"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<template is=\"dom-bind\">\n",
" <urth-core-function ref=\"get_cell\" arg-cell=\"[[sel]]\" result=\"{{r}}\" auto ></urth-core-function>\n",
" <urth-core-dataframe id=\"table\" ref=\"df\" value=\"{{df}}\" auto></urth-core-dataframe>\n",
" <div class=\"card-content\">\n",
" <urth-viz-table datarows=\"{{ df.data }}\" selection=\"{{sel}}\" columns=\"{{ df.columns }}\" rows-visible=3>\n",
" </urth-viz-table>\n",
" </div>\n",
"</template>\n",
"<script>\n",
"document.getElementById('table').addEventListener('selection-index-changed', function(e) {\n",
" console.log('new selectionIndex is: ' + e.detail.value);\n",
"});\n",
"</script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\"A\",1]\n"
]
}
],
"source": [
"%%html\n",
"<template is=\"dom-bind\">\n",
" <urth-core-function ref=\"get_cell\" arg-cell=\"[[sel]]\" result=\"{{r}}\" auto ></urth-core-function>\n",
" <urth-core-dataframe id=\"table\" ref=\"df\" value=\"{{df}}\" auto></urth-core-dataframe>\n",
" <div class=\"card-content\">\n",
" <urth-viz-table datarows=\"{{ df.data }}\" selection=\"{{sel}}\" columns=\"{{ df.columns }}\" rows-visible=3>\n",
" </urth-viz-table>\n",
" </div>\n",
"</template>\n",
"<script>\n",
"document.getElementById('table').addEventListener('selection-index-changed', function(e) {\n",
" console.log('new selectionIndex is: ' + e.detail.value);\n",
"});\n",
"</script>"
]
},
{
"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