'altair chart syntax error when deploying in streamlit

I'm getting an infuriating syntax error in streamlit that I can't figure out. This code works totally fine and displays the chart:

ward_housing_cost = alt.Chart(df_ward).mark_bar().encode(
 alt.X('Ward:N', axis=alt.Axis(format='d')),
 alt.Y('avg_housing_cost_ward:Q', title = 'rating of housing cost', 
 scale=alt.Scale(domain=(0, 5))
 ).properties(title = 'Rating of housing cost by ward')
st.altair_chart(ward_housing_cost)

...but this one gets the syntax error:

ward_streets_sidewalks = alt.Chart(df_ward).mark_bar().encode(
 alt.X('Ward:N'),
 alt.Y('avg_streets_sidewalks_ward:Q', title = 'rating of maintenance of 
 streets/sidewalks')
 ).properties(title = 'Rating of maintenance of streets/sidewalks by ward')
st.altair_chart(ward_streets_sidewalks)

here is what the error looks like:

File "/app/shs2021/streamlit_app.py", line 90
  ward_streets_sidewalks = alt.Chart(df_ward).mark_bar().encode(
                       ^
SyntaxError: invalid syntax

I have tried everything I can think of including rewriting the thing from scratch, renaming the chart, etc.



Solution 1:[1]

The answer is: there WAS a syntax error, but it was in the block of code ABOVE where the error said it was. I didn't realize that was possible; thanks @joelostblom for the heads up.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 midnightradi0