jupyter-widgets / ipywidgets

Interactive Widgets for the Jupyter Notebook
https://ipywidgets.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.1k stars 945 forks source link

Extending jslink? #1109

Open maartenbreddels opened 7 years ago

maartenbreddels commented 7 years ago

jslink is really useful for having some frontend only communication, however there are more use cases I can think of that would be useful. I wonder if some thought went already into this, if not maybe it is useful to discuss some use cases that could be implemented simply.

SylvainCorlay commented 7 years ago

We were thinking of having a js container run an arbitrary js transformation specified in a third transform argument, a bit like in traitlets' link. Security is tricky, but can probably be achieved.

maartenbreddels commented 7 years ago

Been discussing with @SylvainCorlay about transformations, Similar to traitlets, would be nice to have:

jsdlink((slider1, 'index'), (floattext, 'value'), transformation='log(value)')

We probably don't want to use eval, so that leave us to choose a library for parsing that: From http://stackoverflow.com/questions/2276021/evaluating-a-string-as-a-mathematical-expression-in-javascript I found these:

Another option I would like to see, is sth similar, but instead of a math transformation, it's is a non-linear mapping, but an option from say a dict:

animation_delay_toggle_button = widgets.ToggleButtons(
    options=['None', 'Fast, 'Regular', 'Slow'],
    description='Delay:',
)
jsdlink((animation_delay_toggle_button, 'index'), (figure, 'animation_delay'), \
 choice={0:0, 1:100, 2:500, 3:1000})

Using a dict it would also be possible to map strings to values.

Having this in jslink would also be nice, but lets wait the discussion/PR here

ClementPinard commented 3 months ago

Hi, sorry for digging up this topic, but I stumbled upon it when i searched for linking between a checkbox and a stack

Do you know if there have been some work on extending jslink, especially with the dict mapping ?

I know I can use the observe or interactive_output methods, but these require an active python kernel, and I would like it to be available for static widgets, because the notebook is part of a documentation that gets compiled with sphinx.

For now I'm using ToggleButtons that have an index that I can link with my stack, but having a selector only for 2 values is a bit overkill in my case.