Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui.leaflet location is reset when ui.plotly is updated #4182

Open
qutang opened this issue Jan 7, 2025 · 1 comment
Open

ui.leaflet location is reset when ui.plotly is updated #4182

qutang opened this issue Jan 7, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@qutang
Copy link

qutang commented Jan 7, 2025

Description

minimal reproducible code:

import plotly.graph_objects as go
from nicegui import ui
from random import random


@ui.page("/")
async def page():
    m = ui.leaflet(zoom=5)
    central_park = m.generic_layer(
        name="polygon",
        args=[
            [
                (40.767809, -73.981249),
                (40.800273, -73.958291),
                (40.797011, -73.949683),
                (40.764704, -73.973741),
            ]
        ],
    )
    await m.initialized()
    bounds = await central_park.run_method("getBounds")
    m.run_map_method("fitBounds", [[bounds["_southWest"], bounds["_northEast"]]])

    fig = go.Figure()
    fig.update_layout(margin=dict(l=0, r=0, t=0, b=0))
    plot = ui.plotly(fig).classes("w-full h-40")

    def add_trace():
        fig.add_trace(go.Scatter(x=[1, 2, 3], y=[random(), random(), random()]))
        plot.update()

    ui.button("Add trace", on_click=add_trace)


ui.run()

Once I click the button to update the graph, the leaflet map view was reset to the original state before running the map method to fit bounds.

I tested the code on windows platform.

@falkoschindler
Copy link
Contributor

Thanks for reporting this issue, @qutang!

It seems like any update to the ui.plotly element moves the map back to its original location, even when resizing the window so that the plot is affected. I could boil it down to three lines only:

ui.leaflet(zoom=5)
plot = ui.plotly({})
ui.button("Add trace", on_click=plot.update)

@falkoschindler falkoschindler added the bug Something isn't working label Jan 7, 2025
@falkoschindler falkoschindler changed the title Leaflet map view was reset on client side, whenever an irrelevant element update method is called ui.leaflet location is reset when ui.plotly is updated Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants