Skip to content

ipywidgets Output widget not working properly #127

@giswqs

Description

@giswqs

It appears that the ipywidget Output widget is not working properly with Solara. See an example below. The Output widget is added to the map, which is supposed to print out the mouse clicked coordinates. However, Solara prints it in the terminal. Basically, anything sent to the Output widget will not show up. I have several packages that relies on the Output widget heavily. It would be great if Solara can support the ipywidgets Output widget.

Solara example (not working properly)

import ipyleaflet
import solara
import ipywidgets as widgets

zoom = solara.reactive(2)
center = solara.reactive((20, 0))

class Map(ipyleaflet.Map):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.layout.height = '600px'
        # Add what you want below

        label = widgets.Label('Clicked location')
        output = widgets.Output()
        widget = widgets.VBox([label, output])
        control = ipyleaflet.WidgetControl(widget=widget, position='bottomright')
        self.add_control(control)
        
        def handle_interaction(**kwargs):
            latlon = kwargs.get("coordinates")
            if kwargs.get("type") == "click":
                with output:
                    output.clear_output()
                    print(latlon)

        self.on_interaction(handle_interaction)

@solara.component
def Page():
    with solara.Column(style={"min-width": "500px"}):
        solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
        Map.element(
            zoom=zoom.value,
            on_zoom=zoom.set,
            center=center.value,
            on_center=center.set,
            scroll_wheel_zoom=True,

        )
        solara.Text(f"Zoom: {zoom.value}")
        solara.Text(f"Center: {center.value}")

Pure ipyleaflet example (working properly)

import ipyleaflet
import ipywidgets as widgets

class Map(ipyleaflet.Map):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.layout.height = '600px'
        # Add what you want below

        label = widgets.Label('Clicked location')
        output = widgets.Output()
        widget = widgets.VBox([label, output])
        control = ipyleaflet.WidgetControl(widget=widget, position='bottomright')
        self.add_control(control)
        
        def handle_interaction(**kwargs):
            latlon = kwargs.get("coordinates")
            if kwargs.get("type") == "click":
                with output:
                    output.clear_output()
                    print(latlon)

        self.on_interaction(handle_interaction)

m = Map(center=[40,-100], zoom=4)
m

Peek 2023-05-29 00-27

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions