Ipysheet - An Ipywidget based Spreadsheet that works with Panel

IPySheet

I’m preparing an Introduction to Panel talk to Panel and would like to share some of the code examples.

Here it is Ipysheet. In general Panel provides support for Ipywidgets, c.f. Ipywidget Reference Guide.

If you like Panel and this showcase please share on social media. Thanks

import panel as pn
import ipywidgets as ipw
import ipysheet

pn.extension("ipywidgets", sizing_mode="stretch_width")

accent_base_color = "#F08080"

def get_widget(accent_base_color="blue"):
    slider = pn.widgets.FloatSlider(value=10, start=0, end=100)
    sheet = ipysheet.sheet()

    ipysheet.cell(1,1, "Input")
    cell3 = ipysheet.cell(1,2, 42.)
    ipysheet.cell(2,1, "Output")
    cell_sum = ipysheet.cell(2,2, 52., read_only=True, background_color=accent_base_color)

    @pn.depends(slider, cell3, watch=True)
    def calculate(a,b):
        cell_sum.value = a+b

    return pn.Column(slider, sheet)

widget = get_widget(accent_base_color=accent_base_color)
component = pn.panel(widget, height=500, sizing_mode="stretch_both")
template = pn.template.FastListTemplate(
    site="Panel",
    title="IPySheet",
    accent_base_color=accent_base_color,
    header_background=accent_base_color,
    header_accent_base_color="white",
)
template.main.append(component)
template.servable()

Please note as of 20210818 you will need

1 Like

I tried running your script, but I get a 404 error for https://unpkg.com/ipysheet@0.5.0/dist/index.js
However, I see the file in question at
https://unpkg.com/ipysheet@0.5.0/lib/index.js
Any idea how to fix that?

Thanks,
Riziles

Ahhh… I did some digging. Looks like “dist” is hardcoded into ipywidgets_bokeh, so we would need a code update there for ipysheet to work out-of-the box (unless someone changes the folder structure for ipysheet): https://github.com/bokeh/ipywidgets_bokeh/blob/main/ipywidgets_bokeh/src/loader.ts

1 Like

Hi @riziles

Great work. Could you file an issue and draft the solution with ipywidets_bokeh?

I would love to see this solved one day. Thanks.

Hi @riziles

Do we know that it is not ipysheet that should change their url?

Maybe? The “dist” folder doesn’t seem to be a NPM convention, but seems to be pretty standard for traditional embed-js-cdn-link-in-html packages. Based on @philippjfr 's comment here it doesn’t sound like it’s easy to get the ipysheet maintainers to modify there package. Not sure if the Bokeh maintainers would be more accommodating, but I’ll try.

Posted github issue here: ipysheet · Issue #54 · bokeh/ipywidgets_bokeh · GitHub

1 Like

Looks like IPysheet just completed a PR on this: https://github.com/QuantStack/ipysheet/issues/230

Not sure when we’ll see an update to NPM/Unpkg repos.

1 Like

Nice. That would be awesome.

IT’S WORKING!

IT’S WORKING!

Finally!

1 Like

Juhuu. Ipysheet 0.6.0 works with Panel.

import panel as pn
import ipywidgets as ipw
import ipysheet

pn.extension("ipywidgets", sizing_mode="stretch_width")

accent_base_color = "#F08080"

def get_widget(accent_base_color="blue"):
    slider = pn.widgets.FloatSlider(value=10, start=0, end=100)
    sheet = ipysheet.sheet()

    ipysheet.cell(1,1, "Input")
    cell3 = ipysheet.cell(1,2, 42.)
    ipysheet.cell(2,1, "Output")
    cell_sum = ipysheet.cell(2,2, 52., read_only=True, background_color=accent_base_color)

    @pn.depends(slider, cell3, watch=True)
    def calculate(a,b):
        cell_sum.value = a+b

    return pn.Column(slider, sheet)

widget = get_widget(accent_base_color=accent_base_color)
component = pn.panel(widget, height=500, sizing_mode="stretch_both")
template = pn.template.FastListTemplate(
    site="Awesome Panel",
    title="IPySheet 0.6.0 works with Panel",
    accent_base_color=accent_base_color,
    header_background=accent_base_color,
    header_accent_base_color="white",
)
template.main.append(component)
template.servable()

4 Likes