plotly / plotly/plotly.py

Map doesn't recenter after interac with the graph on mobile

未关闭
#4,942 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P3
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

The app works completely fine on computer but has issues recenter on phone after interacing with the map a bit.

Heres a sample app for replicating the issue;

import dash
from dash import dcc, html, Input, Output
import plotly.express as px
import plotly.graph_objects as go

# Create a Dash app
app = dash.Dash(__name__)

# City data with coordinates
cities = {
    "New York": {"lat": 40.7128, "lon": -74.0060},
    "London": {"lat": 51.5074, "lon": -0.1278},
    "Tokyo": {"lat": 35.6895, "lon": 139.6917},
    "Sydney": {"lat": -33.8688, "lon": 151.2093},
    "Toronto": {"lat": 43.651070, "lon": -79.347015},
}

# Initial map centered at a default location
fig = go.Figure(go.Scattermapbox())
fig.update_layout(
    mapbox_style="open-street-map",
    mapbox_center={"lat": 0, "lon": 0},
    mapbox_zoom=1,
)

# App layout
app.layout = html.Div([
    html.H1("City Map Viewer", style={"textAlign": "center"}),
    
    dcc.Dropdown(
        id="city-dropdown",
        options=[{"label": city, "value": city} for city in cities.keys()],
        placeholder="Select a city",
        style={"width": "50%", "margin": "auto"}
    ),
    
    dcc.Graph(id="map", figure=fig)
])

# Callback to update the map based on dropdown selection
@app.callback(
    Output("map", "figure"),
    Input("city-dropdown", "value")
)
def update_map(selected_city):
    if not selected_city:
        return fig  # Return the default map if no city is selected

    # Get the coordinates of the selected city
    city_coords = cities[selected_city]

    # Update the map figure
    new_fig = go.Figure(go.Scattermapbox())
    new_fig.update_layout(
        mapbox_style="open-street-map",
        mapbox_center={"lat": city_coords["lat"], "lon": city_coords["lon"]},
        mapbox_zoom=10,
    )

    # Add a marker for the selected city
    new_fig.add_trace(go.Scattermapbox(
        lat=[city_coords["lat"]],
        lon=[city_coords["lon"]],
        mode="markers",
        marker=dict(size=10, color="red"),
        text=[selected_city],
    ))

    return new_fig

# Run the app
if __name__ == "__main__":
    app.run_server(debug=True)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先运行提供的 Dash 示例,并在手机上复现地图交互,将其与桌面端行为进行比较。跟踪示例的 dcc.Graph 回调中的地图更新和重新居中行为,然后验证在移动设备上进行过先前交互后,选择城市是否能正确地使地图重新居中。

由索引模型根据 Issue 内容生成。

评估

技术栈
plotly, python
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。