emilhe / dash-leaflet

MIT License
213 stars 37 forks source link

Update the positions' property of Polyline through a callback #224

Open namakshenas opened 8 months ago

namakshenas commented 8 months ago

Hi, How is it possible to update the positions property of Polyline through a callback? I tried 'value' and 'data' in the callback's Output property, but it seems it did not work.

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

app = Dash()
app.layout = html.Div(
html.Button(id="btn_run"),
dl.Map(dl.TileLayer(),
dl.Polyline(positions=[], id='position-data'),
center=[56,10], zoom=6, style={'height': '50vh'}))

@app.callback(Output('position-data', 'value'),
              Input("btn_run", "n_clicks"),
              prevent_initial_call=True)
def on_click(n_clicks):
    positions = [[49.799558, 6.712016], [50.58268, 5.549233]]
    return positions

if __name__ == '__main__':
    app.run_server()