Skip to main content

A React.js inspired Component for building a simple reactive UI in Google Colaboratory.

Project description

ColabComponent

A React.js inspired Component for building a simple reactive UI in Google Colaboratory.

Why?

Sometimes there is some manual work that has to be done with your data. Instead of building a custom desktop app, why not do so in Colab?

I built this component inspired by the react framework, which provides in my opinion the best tools for quick prototype-like development ideal for custom data exploring and data analysis tools.

How?

The google.colab package offers an interface to run python functions in the output. Combine that with the fact that python notebooks can render full on HTML and you can build UIs using python, HTML, css and javascript!

Install

In a cell run:

!pip3 install ColabComponent

All the required dependencies are installed in the enviroment provided by google.

How to use?

The package utilises Object-Oriented inheritance and is based around the basic class Component.

Component API

property name type description overridable
render method the basic method, where the ui and effects are defined
component_did_mount method a hook that is called, when the component is mounted
component_did_update method a hook that is called, when the component is updated
display method run to display the component
register_effect method registers a python function such that it can be used within the HTML code
state dict holds the info about the state of the component
set_state method the preferred way of updating the component state

Example

from ColabComponent import Component

class Counter(Component):
  def __init__(self):
    super().__init__()
    self.state = {
        'number': 1
    }

    self.use_add = self.register_effect('add', self.add)

  def render(self):
    return f'''
      <h1>{self.state['number']}</h1>
      <button onclick="{self.use_add()}">+1</button>
    '''

  def component_did_mount(self):
    print('mounted')

  def component_did_update(self):
    print('updated')

  def add(self):
    self.set_state({
        'number': self.state['number'] + 1
    })

Counter().display()

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

ColabComponent-0.0.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file ColabComponent-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: ColabComponent-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4

File hashes

Hashes for ColabComponent-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6173a938868eac422b5f88feaafb1e456a32dce881b3b5e7ada4059043bd32cc
MD5 710b825ed72bc5f5bed3df05ffa54385
BLAKE2b-256 515bed3db53ed75a9187870df9f49f1c59153952a31c4eb9ae125290da94995a

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