How can I set different tooltips for multiple layers on a pydeck streamlit

Hello,

I’ve got two pydeck layers, and I want to show for every layer a different tooltip.

    import streamlit as st

    st.pydeck_chart(
    pdk.Deck(
        map_style="mapbox://styles/mapbox/light-v9",
        initial_view_state=pdk.ViewState(
            latitude=addresses_df["lat"][0],
            longitude=addresses_df["lon"][0],
            zoom=20,
            pitch=50,
        ),
        layers=[
            pdk.Layer(
                "ScatterplotLayer",
                data=flow_df,
                get_position="[lon, lat]",
                get_radius=5,
                pickable=True,
                opacity=0.8,
                stroked=False,
                filled=True,
                wireframe=True,
            ),
            pdk.Layer(
                "HexagonLayer",
                data=data,
                get_position="[lon, lat]",
                radius=2.5,
                elevation_scale=0.1,
                pickable=True,
                extruded=True,
                auto_highlight=True,
                coverage=0.9,
            ),
        ],
        tooltip={
            "html": "<b>adresse:</b> {address}"
            "<br/> <b>mape:</b> {pourc_err}"
            " <br/> <b>count:</b> {flow_value_count} "
            "<br/> <b>prediction:</b> {flow_value_streaming}"
            "<br/> <b>pedestrian ids:</b> {elevationValue}",
            "style": {"color": "white"},
        },
    )
    )

with doing this, I have one tooltip for the two layers. For example, the tooltip for the scatterplotlayer will have all the information except the pedestrian ids, but it will be displayed with pedestrian ids : {elevationValue}

I need to print tooltip only when I have information or show for every layer a different tooltip.

Thank you,

Hi @ojabri and welcome to the forum :wave:,

It looks like Pydeck doesn’t support conditional or multilayer tooltips (https://pydeck.gl/tooltip.html).
Try using Altair charts library which has a multilayer tooltips support.

Please feel free to let us know if you need any additional help.
And thanks for using Streamlit!

1 Like