Animated barchart

I try to create an animated bar chart. Each timestep represents the values for different provinces for a given date. Therefore the classic approach with add_row() does not work, I need to exchange the entire dataset for each timestep. I tried this, but the plot stays unchanged. I was wondering if there is a way of deleting all rows before adding the new data frame using add_row(). Thanks for any suggestions.

chart = get_bar_chart(data_filtered, plot_title, ax_title, marker_col)
st.altair_chart(chart)
progress_timestep_inc = int(1 / len(DATE_LIST) * 100)
progress_timestep = 0
        
for dt in dates:
            data_filtered = data[data['date'] == dt]
            chart.data = data_filtered
            if dt == DATE_LIST[-1] or progress_timestep > 100:
                progress_timestep = 100
            progress_bar.progress(progress_timestep)
            progress_timestep += progress_timestep_inc
            time.sleep(0.2)

Hi @godot63,

Does this example help?

import streamlit as st
import pandas as pd
import numpy as np
import time

i = 0

chart = st.empty()

while i < 5:
  chart_data = pd.DataFrame(np.random.randn(50, 3), columns=["a", "b", "c"])
  chart.bar_chart(chart_data)
  time.sleep(0.5)
  i += 1

If not, please provide fully reproducible sample code so we can copy/paste and run your example.

hi @Jonathan_Rhone, yes that helped. With your example, I finally understood the use of st.empty() and was able to apply it to an Altair chart. Thanks again!