Sonali
Sonali3mo ago

mo.ui.altair_chart(chart) is not updating based on filtered data

I am creating a simple Altair bar chart, want to update it based on a filtered data but it is not getting updated. here is the flow of my code:
6 Replies
Sonali
SonaliOP3mo ago
can anyone please help me witht this
Akshay
Akshay3mo ago
Can you include a minimal example? This notebook is rather long
Sonali
SonaliOP2mo ago
Please find the reduced version of above code here.
Myles Scolnick
Myles Scolnick2mo ago
the code is mutating bar_chart only in the function, and not actually updating the global bar_chart. i would remove the update_chart function and instead let everything run reactively it would reduce the amount of code too. you should only declare once:
bar_chart = alt.Chart(df_agg).mark_bar(size=30).encode(
bar_chart = alt.Chart(df_agg).mark_bar(size=30).encode(
and still have it depend on all of your filters i won't be able to refactor your code, but you should remove the callback and instead let marimo handle updating the affected cells based on changing ui elements
Sonali
SonaliOP2mo ago
Hi @Myles Scolnick Thank you for the suggestion. I have now refactored the code as suggested by you but now I am getting "The variable 'filtered_data' was defined by another cell:" when I do the filteration based on the date range e.g. filtered_data = filtered_data[ (filtered_data["request_date"] >= end_date_str) & (filtered_data["request_date"] <= start_date_str) ]
Myles Scolnick
Myles Scolnick2mo ago
you need to rename the variable