TomJohn
December 6, 2022, 10:36pm
1
Summary
Hello, streamlit community! I’m trying to figure out how to make my app’s user experience better. Any ideas how to define a leafmap with an added shape file, using a geodataframe, in a way that does not require map rendering on recalculation? I’ve tried using session states, but without satisfying results. Please note that I want to color certain counties taking into account parameters from text input, triggering recalculation.
Btw. is
m = leafmap.Map()
m.add_gdf(gdf, layer_name="JPT_NAZWA_")
(...)
m.add_gdf(
gdf.loc[[st.session_state["r_no_col"]]],
layer_name="Selected",
fill_colors=["red"],
)
m.to_streamlit()
Streamlit app
Please note that it takes some time to load & render map
https://powiaty.streamlit.app/
Github
import streamlit as st
import leafmap.foliumap as leafmap
import pycrs
import geopandas as gpd
st.set_page_config(layout="wide")
# Geopandas use
# https://leafmap.org/notebooks/10_add_vector/
# https://leafmap.org/notebooks/13_geopandas/
# @st.cache(allow_output_mutation=True)
@st.experimental_memo
def get_data(file):
geo_df = gpd.read_file(file) # , rows=100)
return geo_df
This file has been truncated. show original
1 Like
Did you see this post? Maybe it will help?
Streamlit-folium 0.8.0 was just released, and it contains new functionality for dynamic maps.
[ezgif-1-0189d7f263]
If you’re only making static maps (not adding/removing/updating things within your app), then you may not make use of this. But, if you’re changing your map (e.g. changing the markers that are on the map, moving to a new location, etc.) via other streamlit widgets, you can now do that without re-drawing the map every time.
The new arguments to st_folium are zoom (takes an int), c…
1 Like