ipyvuetify icon indicating copy to clipboard operation
ipyvuetify copied to clipboard

Update section on embed ipywidgets

Open guimillet opened this issue 4 years ago • 3 comments

In the current example, single_widget is only a class attribute, such that when creating a new instance of MyComponent, the same widget is displayed. The user rather would rather need to have a different instance of single_widget for each instance of MyComponent.

For that, I suggest to initialise the embedded ipywidget of MyComponent within the __init__ function. This also gives the possibility of customising the embedded widget upon instantiating MyComponent, via keyword arguments given to the _init__ function.

The patch also harmonises quote style used in the code example.

guimillet avatar Sep 15 '21 09:09 guimillet

Thanks for your contribution, sorry for the delayed response.

Maybe it's a bit simpler for this example to just set the content when creating MyComponent (also applied to the other 2 widgets):

...
    items = traitlets.List().tag(sync=True, **widgets.widget_serialization)
    single_widget = traitlets.Any().tag(sync=True, **widgets.widget_serialization)
...
MyComponent(
    items=[{
        'title': 'Title 1',
        'content': slider1
    }, {
        'title': 'Title 2',
        'content': slider2
    }],
    single_widget=widgets.IntSlider(description='Single slider', value=40)
)

mariobuikhuizen avatar Oct 21 '21 12:10 mariobuikhuizen

I agree with your suggestion. Shall I update the commit or do you prefer to do it?

guimillet avatar Oct 23 '21 21:10 guimillet

It would be great if you could do it!

mariobuikhuizen avatar Oct 25 '21 09:10 mariobuikhuizen

Thanks @guimillet!

mariobuikhuizen avatar Sep 20 '22 10:09 mariobuikhuizen