Deckgl LineLayer Example

Iโ€™m loving streamlit so far, but have a quick question about using encodings from my dataframe to create a LineLayer in the deckgl chart. If you have an example, that would be helpful.

Here is my current code, but Iโ€™m only getting the lat/lon fields from my dataframe to show up and the target position always appears to be (0,0).

st.deck_gl_chart(
    viewport={
        "mapStyle": "mapbox://styles/mapbox/light-v9",
        "mapboxApiAccessToken": '<token>',
        "latitude": midpoint[0],
        "longitude": midpoint[1],
        "zoom": 2,
        "pitch": 50
    },
    layers=[
        {
            "type": "LineLayer",
            "data": tracks,
            "encoding": {"getLatitude": "lat",
                         "getLongitude": "lon",
                         "getTargetLatitude": "to_lat",
                         "getTargetLongitude": "to_lon",
                        }
        }
    ]
)

Nevermind! I donโ€™t think I need to use Encoding, I can just use the following.

        "type": "LineLayer",
        "data": tracks,
        "getLatitude": "lat",
        "getLongitude": "lon",
        "getTargetLatitude": "to_lat",
        "getTargetLongitude": "to_lon"
1 Like

Awesome, glad you figured it out!

Admittedly, our DeckGL API is not the easiest to use. The problem is that we are trying to convert a JavaScript API that accepts functions as input to a Python API that revolves around dataframes and cannot accept functions. So we had to make some compromises there. Iโ€™m hoping weโ€™ll soon be able to remove those, when switch to using DeckGLโ€™s JSONConverter.