Intermittent syntax error

Summary

I am getting an intermittent Syntax error (Edge):


The error is slightly different with Chrome:

The behaviour is strange, sometimes the page works flawlessly, then it will “fail”, it doesn’t always produce this error on the same component, sometimes a simple line of text will produce the error.
If i do the following code:

st.map(data)
st.map(data)

I will get the error on the first line, but the second will work fine.

I wonder if this is related to st.experimental_data_editor as it is usually the next component after that which fails?

Steps to reproduce

Code snippet:

import streamlit as st
import pandas as pd
import pydeck as pdk
import pyproj

def E_N_to_lat_lon(easting, northing, utm_band):
    # Define the projection
    out_proj = pyproj.Proj(proj='latlong', datum='WGS84')
    in_proj = pyproj.Proj(proj='utm', zone=utm_band, datum='WGS84')    
    # Convert the coordinates
    lon, lat = pyproj.transform(in_proj, out_proj, easting, northing)    
    return(lat, lon)

st.set_page_config(layout="wide")

st.title('SPLAT - CTV Routing Optimisation')

coord_type = st.radio('Coordinate Reference System', 
                      options=['Easting & Northing','Lat/Long'], 
         horizontal=True)

if coord_type == 'Lat/Long':
    input_data = pd.DataFrame({
                "Location Name":str,
                "Latitude":[] ,
                "Longitude":[]})    
else:
    input_data = pd.DataFrame({
                "Location Name":str,
                "Easting":[] ,
                "Northing":[]})
    utm = st.number_input('UTM Zone', min_value=1, max_value=60, step=None, 
                    format=None, key=None, help=None, on_change=None, 
                    args=None, kwargs=None, disabled=False, value=31,
                    label_visibility="visible")
    st.write("Click here for UTM zone map https://www.dmap.co.uk/utmworld.htm")

data = st.experimental_data_editor(input_data, use_container_width=True, 
                                    num_rows="dynamic")

if coord_type != 'Lat/Long':
    data2 = list(zip(data.Easting, data.Northing))
    data2 = [E_N_to_lat_lon(x,y,utm) for x,y in data2]    
else:
    data2 = list(zip(data.Latitude, data.Longitude))

data_df = pd.DataFrame (data2, columns = ['latitude', 'longitude'])
data_df['Location Name'] = data['Location Name']

st.dataframe(data_df)
# st.map(data_df)

st.pydeck_chart(pdk.Deck(
    map_style=None,
    initial_view_state=pdk.ViewState(
        longitude=data_df.longitude.mean(),
        latitude=data_df.latitude.mean(),
        zoom=7,
        min_zoom=2,
        max_zoom=10,
        pitch=0,
        bearing=0
    ),
    layers=[
        pdk.Layer(
            'ScatterplotLayer',
            data=data_df,
            radius_scale=6,
            pickable= True,
            radiusScale= 1,
            radiusMinPixels= 3,
            radiusMaxPixels= 10,
            get_position='[longitude, latitude]',
            get_color='[200, 30, 0]',
        ),
    ],

))

Debug info

  • Streamlit version: 1.19
  • Python version: 3.9.16
  • Using Pip
  • OS version: Windows 10
  • Browser version: Edge 103, Chrome 110

Thank you in advance for any help!

Hi @Edwin_Wilson, welcome to the forum! :wave: :balloon:

Unfortunately, this is a known bug with how Streamlit parses JSON for pydeck:

If the data contains NaN values, you will see the error from the screenshots you’ve shared.

Community voting on bug reports enables the Streamlit team to prioritize which bugs are most urgent to our users.

If you’d like the Streamlit team to prioritize a fix for this, please use the :+1: (thumbs up emoji) reaction in response to the issue on GitHub.

Thank you! I did search but didn’t manage to find this issue.
I have pre-poulated with zeros and it seems to be working.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.