With the above dataset (both dates treated as strings), I am trying to create a heatmap chart altair. It needs to have interactivity, but when I add it via .add_params()
the chart stops working, showing nothing at all.
Code:
selection_point = alt.selection_point(name="selected-point")
heatmap = alt.Chart(heatmap_data).mark_rect().encode(
x=alt.X('departureTime_Inbound:O', title='Inbound Date'),
y=alt.Y('departureTime_Outbound:O', title='Outbound Date'),
color=alt.Color('Number of Flights:Q', scale=alt.Scale(scheme='blues')),
tooltip=['departureTime_Outbound', 'departureTime_Inbound', 'Number of Flights']
).properties(
width=800,
height=600,
title="Flight Prices Heatmap"
).add_params(selection_point)
# Display the heatmap in Streamlit
data = st.altair_chart(heatmap, on_select="rerun")
st.write(data)
With selection parameter, the chart is as below
Without it (and without on_select
argument on st.altair_chart()
)