Hello,
I’m trying to draw a bar chart using vega_lite_chat() function with data determined by a selectbox but without succes. When I change the value of the checkbox, the others charts changed but not the vega_lit_chart. I added an altair chart just after which works.
The code
dep = st.selectbox('Liste des départements', listdep)
if dep:
st.header('Tests / Cas positifs')
data = data[(data['dep'] == dep) & (data['cl_age90'] == 0)]
data = data.rename(columns={'P': 'Positifs'})
data = data.rename(columns={'T': 'Tests'})
data = data.rename(columns={'jour': 'Date'})
st.vega_lite_chart(data, {
"width": 600,
"height": 350,
'encoding': {
'x': {'field': 'Date', 'type': 'temporal', 'title': 'Date'}
},
'layer': [{
"mark": {'type': 'bar', 'color': 'red', 'tooltip': True},
'encoding': {
'y': {'field': 'Positifs', 'type': 'quantitative'}
}
},
{
'mark': {'type': 'bar', 'color': 'green', 'opacity': 0.3, 'tooltip': True},
'encoding': {
'y': {'field': 'Tests', 'type': 'quantitative'}
}
}]
})
c = alt.Chart(data).mark_bar(opacity=0.7).encode(
x='Date',
y='Positifs',
color='Tests'
)
st.altair_chart(c, use_container_width=True)
You can watch the result on http://ml.madpowah.org then go on the menu “Etat actuel par département”
Thank you for your help