emilhe / dash-leaflet

MIT License
204 stars 33 forks source link

Cannot change colour of markers in callback in 1.0.11 #215

Open parallelepiped12 opened 8 months ago

parallelepiped12 commented 8 months ago

Changing the colour of CircleMarker objects in a callback does not seem to work in 1.0.11, but it works correctly in 0.1.23. Minimal example:

from dash import Dash, html, callback, Output, Input
import dash_leaflet as dl

# Initialize the app
app = Dash(__name__)

# App layout
app.layout = html.Div([
    html.Div(children="Weird Behaviour"),
    html.Hr(),
    dl.Map(center=[0, 0], zoom=10, style={'height': '90vh'}, id='map'),
    html.Button('Break It!', id='break-button')
])

@callback(
    Output(component_id='map', component_property='children'),
    Input(component_id='break-button', component_property='n_clicks')
)
def break_map(n_clicks):
    if n_clicks is None:
        map_components = [
            dl.TileLayer(),
            dl.CircleMarker(radius=2, center=(0, 0),
                            color='rgb(255, 0, 0)'
                            ),
            dl.CircleMarker(radius=2, center=(0.1, 0),
                            color='rgb(0, 255, 0)'
                            ),
            dl.CircleMarker(radius=2, center=(0, 0.1),
                            color='rgb(0, 0, 255)'
                            ),
        ]
    else:
        map_components = [
            dl.TileLayer(),
            dl.CircleMarker(radius=2, center=(0, 0),
                            color='rgb(255, 0, 0)'
                            ),
            dl.CircleMarker(radius=2, center=(0, 0.1),
                            color='rgb(0, 0, 255)'
                            ),
        ]
    return map_components

# Run the app
if __name__ == '__main__':
    app.run(debug=True)

The marker will have the same colour as the marker in the corresponding position in map_components initially.

ougx commented 2 months ago

I have the same problem.