How to embed a dropdown ipywidget in an ipysheet spreadsheet?

Viewed 57

I tried following the code to merge a dropdown menu ipywidget into the ipysheet. it seems like my code works the way I imagined. However, I am unable to select items from the menus listed in the dropdown widget.

import ipysheet
import ipywidgets as widgets

Solvent = widgets.Dropdown(
    options=['DMC', '2-Butanol', 'Chloroform', 'Ethanol'],
    value='DMC',)

sheet2 = ipysheet.sheet()
ipysheet.column(0, [Solvent])
ipysheet.column(1, [1,2,3,4, 5])


widgets.VBox([sheet2, Solvent ])
1 Answers

After some review, I believe that this is a genuine bug/shortcoming with ipysheet. Though there are alternative approaches, this inability to use a particular widget within ipysheet cells is not an expected result of this API... Someone please correct me if I'm missing something.

There is a "hack" that is working for me through Jupyter Notebook in the browser, which is to right-click the dropdown before left-clicking it to change the context of the dropdown menu, allowing you to select it via mouseover.

gif animation of right-click dropdown hack

The other alternative is passing in your options as the "choice" argument to the cell you wish to contain the dropdown.

from ipywidgets import link
import ipysheet 
import ipywidgets as widgets

Solvent = widgets.Dropdown(
    options=['DMC', '2-Butanol', 'Chloroform', 'Ethanol'],
    value='DMC',)

sheet2 = ipysheet.sheet()

# dropdown_cell = ipysheet.cell(0,0,choice = Solvent.options,value='WORLD')
interactive_cell = ipysheet.cell(1,3, value='HELLO')
dropdown_cell = ipysheet.cell(0,0,choice = Solvent.options,value='WORLD')

# link((interactive_cell,'value'),(dropdown_cell,'value'))
link((dropdown_cell,'value'),(interactive_cell,'value'))


widgets.VBox([sheet2, Solvent ])

From my current understanding (and attempts), only cells are interactive in ipysheets. (The alternative method of using the ipysheet "calculation" decorator also depends on the items being Cells, not Columns.)

Related