Can values ​​from IPython widgets propagate to other cells?

Is it possible for values ​​from IPython widgets to propagate to other cells without reloading those cells further downstream?

In particular, I have some checkboxes that indicate if certain lines should be plotted in each plot. I have several charts and I would like to have the charts in separate cells so that I can provide a textual description of what is in each plot. The rough structure of what I represent is shown below, with each numbered item in the list being a different cell.

  • Markdown - Select each of the lines you want to build from the checkboxes below.
  • Code - interactive(some_plotting_fn, ckbox1=CheckboxWidget(), ckbox2=CheckboxWidget())

  • Markdown - description of the first chart. Blah blah.
  • Code - plot_first_chart_based_on_check_boxes()

  • Markdown - description of the second chart. Blah blah blah.
  • Code - plot_second_chart_based_on_check_boxes()

Is it possible? I could do the whole plot in one cell, but then the plots end up grouped together and I would prefer the text describing the diagrams to represent them.

+3


source to share


1 answer


Create checkbox

as separate objects:

from IPython.html.widgets import interactive, Checkbox
c= Checkbox()
interactive(lambda x,y: print(x,y), x=c, y=Checkbox())
----
display X and Y checkbox

      

Here are some markdowns ....

interactive(lambda x,y: print(x,z), x=c, z=Checkbox())
----
display X and Z checkbox

      



There are more markdowns here, I won't be using interactive, so you'll need to rerun the cell to see the changes:

if x is True:
   title('is is True')
plot(...)

      

The X checkbox syncs across cells (at least on the IPython host) replace print with your plotting functions. You can also access the "x" value on c.value

.

[edit] To respond to people's suggestions, follow these steps: Note that the suffix has Widget

been removed in major and future versions of IPython . The API with suffixes throughout was provisional and was never considered final. Therefore the correct usage is valid checkbox

, not CheckboxWidget

.

+1


source







All Articles