Firstly, thanks to this amazing library, I really enjoy the way it is implemented.
In a dash application with a Map component containing a LayersControl object initialized in a previous callback with different layers, I wan’t to add another layer from a second callback but when I am passing the children property of the LayersControl I got a cyclic object value error.
Here is the way I declare my map component and the LayerControl object
dl.Map(
id="maps",
children = [dl.LayersControl(id = 'layers', children = [])],
zoom=4, preferCanvas=True, zoomControl = False,
style={
'width': '1200px',
'height': '720px'
},
),
Then in a first callback I add several layers
@app.callback(
Output('layers', 'children'),
)
my_first_callback() :
maps = [
dl.BaseLayer(
dl.TileLayer(
url = tileProvider.url.format(x="{x}", y="{y}", z="{z}", s="{s}", r=tileProvider.get("r", ""), **tileProvider),
attribution="IGN"),
name = 'fond de carte', checked = True
),
dl.Overlay(dl.LayerGroup(layer1), name = 'layer1', checked = True),
dl.Overlay(dl.LayerGroup(layer2), name = 'layer2', checked = True),
dl.Overlay(dl.LayerGroup(layer3), name = 'layer3', checked = False),
]
return maps
Then I’m trying to update my LayersControl in a second callback
@app.callback(
Output('layers', 'children'),
State('layers', 'children'),
)
my_second_callback(layer_to_update) :
# some code
return layer_to_update
The app can’t enter the callback cause line State('layers','children')
rise cyclic object value error. I was previously using only a LayerGroup in the map children property to add different layers. It was working perfectly but I wanted the possibility to hide/show layers and I don’t understand why it is not working anymore, or maybe I am not using the correct workflow to do this.
Thanks !