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

Swapping Colorbar Component: t is not a function #271

Open
leoduret opened this issue Feb 17, 2025 · 1 comment
Open

Swapping Colorbar Component: t is not a function #271

leoduret opened this issue Feb 17, 2025 · 1 comment

Comments

@leoduret
Copy link

Hi,

I am trying to swap the colorbar depending on the feature displayed on the map. Whenever I replace a categorical Colorbar by a continuous one I get this error:

TypeError: t is not a function
    at i._update (dash_leaflet.v1_0_15m1734008440.js:2:291829)
    at i.setClasses (dash_leaflet.v1_0_15m1734008440.js:2:292916)
    at dash_leaflet.v1_0_15m1734008440.js:2:293924
    at dash_leaflet.v1_0_15m1734008440.js:2:264020
    at commitHookEffectListMount ([email protected]_18_2m1734008463.14.0.js:19866:28)
    at commitPassiveHookEffects ([email protected]_18_2m1734008463.14.0.js:19904:13)
    at HTMLUnknownElement.callCallback ([email protected]_18_2m1734008463.14.0.js:182:16)
    at Object.invokeGuardedCallbackDev ([email protected]_18_2m1734008463.14.0.js:231:18)
    at invokeGuardedCallback ([email protected]_18_2m1734008463.14.0.js:286:33)
    at flushPassiveEffectsImpl ([email protected]_18_2m1734008463.14.0.js:22988:11)

I believe the issue comes from the this._update() call in the setters not allowing the replacement of all colorbar properties to a coherent state before updating.

Can you confirm this on your side? If so it I believe it would be good to allow for users to be able swap the colorbar on the map.

Thanks in advance

Léo

@leoduret
Copy link
Author

leoduret commented Feb 17, 2025

Minimum reproducible example

"""Minimal reproducible example for a colorbar replacement issue."""

import dash
from dash import Dash, html
from dash_leaflet import Colorbar, Map, TileLayer

d = Dash()

d.layout = html.Div(
    [
        html.Button("Replace Colorbar", id="button", n_clicks=0),
        Map(
            [TileLayer(), html.Div(id="colorbar")],
            style={"height": "50vh", "width": "50vh"},
        ),
    ]
)


@dash.callback(
    dash.Output("colorbar", "children"),
    dash.Input("button", "n_clicks"),
)
def replace_colorbar(n_clicks):
    """Replace the colorbar with a new one."""
    shared = {"position": "topleft", "width": 200, "height": 50, "min": 0, "max": 1}

    if n_clicks % 2 == 0 or n_clicks is None:  # categorical colorbar
        return Colorbar(
            colorscale=["black", "#fdd49e", "rgba(255,0,0,0.35)"],
            classes=3,
            tickDecimals=[1, 2, 3],
            tickValues=[0.1, 0.2, 0.3],
            tickText=[0.1, 0.2, 0.3],
            **shared,
        )
    else:  # continuous colorbar
        return Colorbar(
            colorscale="Viridis",
            **shared,
        )


d.run(debug=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant