1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] ipywidgets interactive with variable containers of widgets

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024 às 14:53.

  1. Stack

    Stack Membro Participativo

    For some interactive data analysis with Jupyter and ipywidgets, I generate a number of widgets depending on the data.

    I.e. eventually I have a number of GridBoxes with Checkboxes, RangeSliders and ColorPickers which I layout in a Tab-Widget.

    Now I tried to use

    categories = ["A", "B", "C"] # retrieve from dataset
    cbox = widgets.GridBox(children=[ widgets.Checkbox(value=True, description=v) for v in categories ])
    rbox = widgets.GridBox(children=[ widgets.IntRangeSlider(value=[1,10], max=20, min=0, description=v) for v in categories ])


    def analysis(variables, ranges):
    print("Hello. Currently I do nothing with the input!")

    display(widgets.Tab(children=[cbox, rbox], titles=('Variables', 'Ranges')))
    display(widgets.interactive_output(analysis, {"variables":cbox, "ranges":rbox}))


    Which does not work:

    AttributeError: 'GridBox' has no attribute 'value'


    I also tried:

    display(widgets.interactive_output(analysis, {"variables":cbox.children, "ranges":rbox.children}))


    which also does not work.

    Is it somehow possible to pass any type of container of some sort to my interactivized function, or do I need to ressort to kwargs? And if so, how would you do that efficiently?


    I use ipywidget version 8.1.5

    Continue reading...

Compartilhe esta Página