ipysheet#

ipysheet connects ipywidgets with tabular data. It basically adds two widgets: a Cell widget and a Sheet widget. There are also auxiliary functions for creating table rows and columns as well as for formatting and designing cells.

Installation#

ipysheet can be easily installed with Pipenv:

$ pipenv install ipysheet

Import#

[1]:
import ipysheet

Cell formatting#

[2]:
sheet1 = ipysheet.sheet()
cell0 = ipysheet.cell(0, 0, 0, numeric_format='0.0', type='numeric')
cell1 = ipysheet.cell(1, 0, "Hello", type='text')
cell2 = ipysheet.cell(0, 1, 0.1, numeric_format='0.000', type='numeric')
cell3 = ipysheet.cell(1, 1, 15.9, numeric_format='0.00', type='numeric')
cell4 = ipysheet.cell(2, 2, "14-02-2019", date_format='DD-MM-YYYY', type='date')

sheet1

Examples#

Interactive table#

[3]:
from ipywidgets import FloatSlider, IntSlider, Image

slider = FloatSlider()
sheet2 = ipysheet.sheet()
cell1 = ipysheet.cell(0, 0, slider, style={'min-width': '122px'})
cell3 = ipysheet.cell(1, 0, 42., numeric_format='0.00')
cell_sum = ipysheet.cell(2, 0, 42., numeric_format='0.00')

@ipysheet.calculation(inputs=[(cell1, 'value'), cell3], output=cell_sum)
def calculate(a, b):
    return a + b

sheet2

Numpy#

[4]:
import numpy as np
from ipysheet import from_array, to_array

arr = np.random.randn(6, 10)

sheet = from_array(arr)
sheet
[5]:
arr = np.array([True, False, True])

sheet = from_array(arr)
sheet
[6]:
to_array(sheet)
[6]:
array([[ True],
       [False],
       [ True]])

Plot editable tables#

[8]:
import numpy as np
from traitlets import link
from ipywidgets import HBox
import bqplot.pyplot as plt
from ipysheet import sheet, cell, column

size = 18
scale = 100.
np.random.seed(0)
x_data = np.arange(size)
y_data = np.cumsum(np.random.randn(size)  * scale)

fig = plt.figure()
axes_options = {'x': {'label': 'Date', 'tick_format': '%m/%d'},
                'y': {'label': 'Price', 'tick_format': '0.0f'}}

scatt = plt.scatter(x_data, y_data, colors=['red'], stroke='black')
fig.layout.width = '70%'

sheet1 = sheet(rows=size, columns=2)
x_column = column(0, x_data)
y_column = column(1, y_data)

link((scatt, 'x'), (x_column, 'value'))
link((scatt, 'y'), (y_column, 'value'))

HBox((sheet1, fig))

For further reading#