How to make pydeck_chart Hexagon layer bar height based on column value

I have a column in my .csv file I want to use to determine the bar height in my pydeck_chart Hexagon layer. So instead of having multiple rows with the same longitude and latitude, each coordinates are in the file just once and thereā€™s a column thatā€™s supposed to determine the height.

Deck.gl seems to have a attribute getElevationHeight thatā€™s supposed to work, but I canā€™t for the life of me figure out how it works through Streamlit and pydeck_chart.

I found a question here with a similar problem, but itā€™s using deprecated deck_gl_chart: How to make Hexagon Layer height value based, and I couldnā€™t get it to work anywayā€¦

Hereā€™s my code:

st.pydeck_chart(pdk.Deck(
    map_style='mapbox://styles/mapbox/light-v9',
    initial_view_state=pdk.ViewState(
        latitude=64.5,
        longitude=25,
        zoom=4,
        pitch=40,
    ),
    layers=[
        pdk.Layer(
            'HexagonLayer',
            data=get_data(),
            get_position='[longitude, latitude]',
            get_elevation_value='sensorValue',    # <- Does not work
            radius=3000,
            elevation_scale=20,
            elevation_range=[1, 10000],
            extruded=True,
        )
    ]    
))

Hereā€™s a look how my csv file looks like:
sensorValue,longitude,latitude
166,25.689529,60.417002000000004
303,24.664459,60.153502
416,24.849501,60.3
ā€¦

I guess this is more of a Pydeck question than Streamlit question but seeing thereā€™s such an active and helpful community I decided to try here! Do you know how to make it work?

Answering myself if anyone is reading this:

ColumnLayer seems to be more what Iā€™m after. A ColumnLayer with similar settings and get_elevation set to the column name seems to do the trick, and provide very similar functionality to HexagonLayer.

It would still be interesting to hear what Iā€™m doing wrong with the HexagonLayer, if anyone has the answer!

3 Likes

You wrote such a nice thing, and then none of us responded :cry:

Have you tried our example from the docs, just to make sure this works at all in your app before customization?

Thanks for the reply!

Yeah, the example works. I think I got the idea of the layer wrong. While HexagonLayer is expecting a separate row for each point and calculates the height of the bar from the number of rows, ColumnLayer is more directed to my case when there is one row per bar, with the height value included in the row.

So maybe I shouldnā€™t force the poor HexagonLayer to be something it doesnā€™t want to be. Weā€™re happy together now with ColumnLayer, and I think thatā€™s better for all of us.

1 Like