Skip to main content

Bring the power of Handsontable to Python and Jupyter Notebook

Project description

pyhandsontable

Build Status PyPI version shields.io PyPI license PyPI pyversions

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)
  • 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;
  }
}

Post-creation editing of the HTML

You might try from bs4 import BeautifulSoup:

        config = {
            'colHeaders': ['id'] + list(CardTuple._fields),
            'columns': [
                {'data': 0},
                {'data': 1, 'renderer': 'markdownRenderer'},
                {'data': 2, 'renderer': 'markdownRenderer'},
                {'data': 3},
                {'data': 4}
            ]
        }
        
        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,
                               config=config,
                               filename=filename,
                               autodelete=False)
            with open(filename, 'r') as f:
                soup = BeautifulSoup(f.read(), 'html.parser')

            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')
            soup.body.insert(soup.body.contents.index(script_tag) + 1, div)

            with open(filename, 'w') as f:
                f.write(str(soup))

            return table
        finally:
            Timer(5, os.unlink, args=[filename]).start()

Source

Screenshots

Related projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhandsontable-0.2.5.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhandsontable-0.2.5-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file pyhandsontable-0.2.5.tar.gz.

File metadata

File hashes

Hashes for pyhandsontable-0.2.5.tar.gz
Algorithm Hash digest
SHA256 1c5ad8cb4cd277d2e3e24be200df5b4bfab87894dac9a5922b4538cae1a676f6
MD5 bda459ee128e758de8b56e3017455d4a
BLAKE2b-256 2cd4a41305fd72d8cc2f80bb56d6edd386564a4c1f1b3294b5e437b9d7a91632

See more details on using hashes here.

File details

Details for the file pyhandsontable-0.2.5-py3-none-any.whl.

File metadata

File hashes

Hashes for pyhandsontable-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 54b4b5d11e6b0a26927edc926c99b20b4a5b63e40255266b491a021ad9124f42
MD5 d2af0c7172ade08be1f69d67292932ab
BLAKE2b-256 8bcf2b38a1b380edf6e7b47199720a75df2cb154152d92d0e3bc729823c86db5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page