https://github.com/patarapolw/pyhandsontable
View a list of JSON-serializable dictionaries or a 2-D array, in HandsOnTable, in Jupyter Notebook.
https://github.com/patarapolw/pyhandsontable
handsontable jupyter-notebook
Last synced: 9 months ago
JSON representation
View a list of JSON-serializable dictionaries or a 2-D array, in HandsOnTable, in Jupyter Notebook.
- Host: GitHub
- URL: https://github.com/patarapolw/pyhandsontable
- Owner: patarapolw
- License: mit
- Created: 2018-07-23T20:16:05.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-11T08:30:50.000Z (over 7 years ago)
- Last Synced: 2025-09-20T04:53:05.733Z (10 months ago)
- Topics: handsontable, jupyter-notebook
- Language: Python
- Homepage:
- Size: 1.23 MB
- Stars: 13
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pyhandsontable
[](https://travis-ci.org/patarapolw/pyhandsontable)
[](https://pypi.python.org/pypi/pyhandsontable/)
[](https://pypi.python.org/pypi/pyhandsontable/)
[](https://pypi.python.org/pypi/pyhandsontable/)
View a list of JSON-serializable dictionaries or a 2-D array, in HandsOnTable, in Jupyter Notebook.
Nested JSON renderer is also supported and is default. Image and markdown renderers are possible, but has to be extended.
## Installation
```commandline
pip install pyhandsontable
```
## Usage
In Jupyter Notebook,
```python
>>> from pyhandsontable import PagedViewer
>>> viewer = PagedViewer(data=data_matrix, **kwargs)
>>> viewer
'A Handsontable is shown in Jupyter Notebook.'
>>> viewer.view(-1)
'The last page is shown.'
>>> viewer.previous()
'The previous page (i-1) is shown.'
>>> viewer.next()
'The next page (i+1) is shown.'
```
Data matrix can be either a list of lists (2-D array) or a list of dictionaries.
It is also possible to view all entries at once, but it could be bad, if there are too many rows.
```python
>>> from pyhandsontable import view_table
>>> view_table(data_matrix, **kwargs)
```
## Acceptable kwargs
- height: height of the window (default: 500)
- width: width of the window (default: 1000)
- 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')
- 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:
```javascript
{
data: data,
rowHeaders: true,
colHeaders: true,
columns: columns,
manualColumnResize: true,
manualRowResize: true,
renderAllRows: true,
modifyColWidth: (width, col)=>{
if(width > maxColWidth) return maxColWidth;
},
afterRenderer: (td, row, column, prop, value, cellProperties)=>{
td.innerHTML = '
' + td.innerHTML + '';
}
}
```
`renderers` example, if your data is a 2-D array:
```python
{
1: 'html',
2: 'html'
}
```
or if your data is list of dict:
```python
{
"front": 'html',
"back": 'html'
}
```
## Enabling Image, HTML and Markdown renderer
This can be done in Python side, by converting everything to HTML. Just use [any markdown for Python library](https://github.com/Python-Markdown/markdown).
```python
from markdown import markdown
import base64
image_html = f'
'
image_html2 = f'
'
markdown_html = markdown(markdown_raw)
```
Any then,
```python
PagedViewer(data=data_matrix, renderers={
"image_field": "html",
"html_field": "html",
"markdown_field": "html"
})
```
## Screenshots


## Related projects
- [htmlviewer](https://github.com/patarapolw/htmlviewer) - similar in concept to this project, but does not use HandsOnTable.js
- [TinyDB-viewer](https://github.com/patarapolw/tinydb-viewer) - uses HandsOnTable.js and also allow editing in Jupyter Notebook.
## License
This software includes [`handsontable.js`](https://github.com/handsontable/handsontable), which is MIT-licensed.