Plotly Expess Choropleth Map Streamlit Optimization

Hello,

Any idea how to optimize the code below so the map will render faster? It takes at least 30s for the map to show. Other graphs are okay.

ct_geo.json is about 4MB

@st.cache_data(ttl=60*60, show_spinner=False)
def load_geo_json():
    file_contents = open('assets/ct_geo.json', 'r')
    return json.loads(file_contents.read())

zipcodes = load_geo_json()

fig = px.choropleth(df_active_num_dynamic, 
                                geojson=zipcodes, 
                                locations='postalcode', 
                                color='Active',
                                color_continuous_scale="Sunset",
                                range_color=(0, df_active_num_dynamic['Active'].max()),
                                featureidkey="properties.ZCTA5CE10",
                                scope="usa",
                                custom_data=["postalcode", "Active", "city",]
                                # labels={'Active':'# of Active Listings'}
                                )

            fig.update_geos(fitbounds="locations")
            fig.update_traces(
                hovertemplate="<br>".join([
                    "Zip Code: %{customdata[0]}",
                    "# of Actives: %{customdata[1]}",
                    "City: %{customdata[2]}",
                ])
            )

            fig.update_layout(height=500, margin={"r":0,"t":0,"l":0,"b":0})
            st.plotly_chart(fig, use_container_width=True)

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