Here is relevant details:
I have two widgets (one dropdown and another html text). My uses will change the value from dropdown and will expect to see the effect in html text.
Additional note 1 : my current development uses interact() function. It will be great help if you enable me to persist the current structure.
Additional note 2 : I need to make sure that the development is fit for both python 2 and 3.
Here is the relevant architecture:
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
def coreCalculationFunction(wantToUpdateIt,myOptions):
if myOptions is 'a':
wantToUpdateIt='first alphabet in english'
elif myOptions is 'b':
wantToUpdateIt='second alphabet in english'
else:
wantToUpdateIt='anything else here!'
return myOptions
def optionsRelatedFunction():
myOptions=['a', 'b', 'c']
wantToUpdateIt=widgets.HTML(value="Hello World")
res=interact(coreCalculationFunction,
wantToUpdateIt=wantToUpdateIt,
myOptions=myOptions);
return res
optionsRelatedFunction()
Thank you very much for your kind help.
Best regards,
Malitha Humayun Kabir
You can use traitlets.link
to connect two values together.
from IPython.display import display
import ipywidgets as W
from traitlets import link
def coreCalculationFunction(myOptions):
return myOptions
def optionsRelatedFunction():
myOptions=['a', 'b', 'c'
]
label = W.HTML(value="Hello World")
the_interact = W.interactive(coreCalculationFunction,
myOptions=myOptions)
dropdown = the_interact.children[0]
# link ensures that when dropdown.value changes,
# label.value gets the same value, and vice versa.
# dlink is a unidirectional alternative.
link((dropdown, 'value'),
(label, 'value'),
)
display(label, the_interact)
optionsRelatedFunction()
-MinRK
--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/c36112ea-bcdf-4fa1-963e-6efd601fb2f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.