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!

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?

https://docs.streamlit.io/en/stable/api.html?highlight=pydeck#streamlit.deck_gl_chart

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