Bring the power of Handsontable to Python and Jupyter Notebook
Project description
pyhandsontable
View a 2-D array, probably from pyexcel in Jupyter Notebook, and export to *.html
.
Installation
pip install pyhandsontable
Usage
>>> from pyhandsontable import view_table >>> view_table(width=800, height=500, data=data_matrix, **kwargs) A Handsontable is shown in Jupyter Notebook.
Acceptable kwargs
- title: title of the HTML file
- maxColWidth: maximum column width. (Default: 200)
- renderers: the renderers to use in generating the columns (see below.)
- autodelete: whether the temporary HTML file should be autodeleted. (Default: True)
- filename: filename of the temporary HTML file (default: 'temp.handsontable.html')
- css: url of the Handsontable CSS
- js: url of the Handsontable Javascript
- config: add additional config as defined in https://docs.handsontable.com/pro/5.0.0/tutorial-introduction.html
- This will override the default config (per key basis) which are:
{ data: data rowHeaders: true, colHeaders: true, dropdownMenu: true, filters: true, modifyColWidth: function(width, col){ if(width > maxColWidth) return maxColWidth; } }
renderers
example, if your data is a 2-D array:
{ 1: 'html', 2: 'html' }
or if your data is list of dict:
{ "front": 'html', "back": 'html' }
Post-creation editing of the HTML
You might try from bs4 import BeautifulSoup
:
renderers = {
1: 'markdownRenderer',
2: 'markdownRenderer'
}
config = {
'colHeaders': ['id'] + list(CardTuple._fields),
'rowHeaders': False
}
filename = 'temp.handsontable.html'
try:
table = view_table(data=([[i] + list(record.to_formatted_tuple())
for i, record in self.find(keyword_regex, tags)]),
width=width,
height=height,
renderers=renderers,
config=config,
filename=filename,
autodelete=False)
with open(filename, 'r') as f:
soup = BeautifulSoup(f.read(), 'html5lib')
div = soup.new_tag('div')
js_markdown = soup.new_tag('script',
src='https://cdn.rawgit.com/showdownjs/showdown/1.8.6/dist/showdown.min.js')
js_custom = soup.new_tag('script')
with open('gflashcards/js/markdown-hot.js') as f:
js_custom.append(f.read())
div.append(js_markdown)
div.append(js_custom)
script_tag = soup.find('script', {'id': 'generateHandsontable'})
soup.body.insert(soup.body.contents.index(script_tag), div)
with open(filename, 'w') as f:
f.write(str(soup))
return table
finally:
Timer(5, os.unlink, args=[filename]).start()
Screenshots
Related projects
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size pyhandsontable-0.2.10-py3-none-any.whl (11.4 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |
Filename, size pyhandsontable-0.2.10.tar.gz (5.9 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for pyhandsontable-0.2.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d9ec731689e9a4f94835b05f9568e72cf1a2aed6d128f4aa748885c98f6a1e1 |
|
MD5 | 86ece15f2514bdf385dd24e3b7c4122f |
|
BLAKE2-256 | 48539c907f85aede57dab004bb987fd5cd47cd2c2758ed71d741dbd224b01676 |