0

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.

  • 1
    It is likely something before that code chunk that is incorrect, such as a missing/unclosed parenthesis or similar. Could you add some of the code above? You can also [read here for common reasons to see that error message](https://realpython.com/invalid-syntax-python/) and consider installing Python 3.10 which gives you [more informative error messages](https://godatadriven.com/blog/python-3-10-introduces-better-error-messaging/). – joelostblom Apr 29 '22 at 14:36

1 Answers1

0

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.