Get help from the marimo community

Updated 3 months 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:
S
A
M
9 comments
can anyone please help me witht this
Can you include a minimal example? This notebook is rather long
Please find the reduced version of above code here.
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:
Plain Text
 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
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)
]
you need to rename the variable
Add a reply
Sign up and join the conversation on Discord