Shared streamlit with geopandas

https://share.streamlit.io/alibama/streamlit-example

i’m just trying to load some shape files in to streamlit and want to use geopandas to read the files in from github where i’ve added them…

i’ve got the following libraries in my requirements.txt file

altair
pandas
streamlit
shapely
fiona
pyproj
gdal
geopandas
and am getting the following error

File "/home/appuser/.local/lib/python3.7/site-packages/streamlit/script_runner.py", line 332, in _run_script
    exec(code, module.__dict__)
File "/app/streamlit-example/streamlit_app.py", line 41, in <module>
    city = gpd.read_file("https://github.com/alibama/streamlit-example/blob/master/planning_area_09_03_2020.shp")
File "/home/appuser/.local/lib/python3.7/site-packages/geopandas/io/file.py", line 96, in _read_file
    with reader(path_or_bytes, **kwargs) as features:
File "/home/appuser/.local/lib/python3.7/site-packages/fiona/collection.py", line 556, in __init__
    encoding='utf-8', **kwds)
File "/home/appuser/.local/lib/python3.7/site-packages/fiona/collection.py", line 162, in __init__
    self.session.start(self, **kwargs)
File "fiona/ogrext.pyx", line 540, in fiona.ogrext.Session.start
File "fiona/_shim.pyx", line 81, in fiona._shim.gdal_open_vector

Hi @alibama, welcome to the Streamlit community!

Can you share more of the error message? It’s not really clear from what you posted what Python is objecting to.

Hi @randyzwitch - i think the issue is with the fiona library - i’m trying to open files and i think fiona wants to do some file conversion juju on the back end? so maybe it’s a file system issue?

i dunno… shape files are common (but they are also proprietary BS, so there’s that…). i’m going to look and see if i can get the data in geojson and if that works i’ll post that approach on here for the next soul :slight_smile:

File "/home/appuser/.local/lib/python3.7/site-packages/streamlit/script_runner.py", line 332, in _run_script
    exec(code, module.__dict__)File "/app/streamlit-example/streamlit_app.py", line 43, in <module>
    test = gpd.read_file("https://github.com/alibama/streamlit-example/raw/master/planning_area_09_03_2020.shp")File "/home/appuser/.local/lib/python3.7/site-packages/geopandas/io/file.py", line 96, in _read_file
    with reader(path_or_bytes, **kwargs) as features:File "/home/appuser/.local/lib/python3.7/site-packages/fiona/collection.py", line 556, in __init__
    encoding='utf-8', **kwds)File "/home/appuser/.local/lib/python3.7/site-packages/fiona/collection.py", line 162, in __init__
    self.session.start(self, **kwargs)File "fiona/ogrext.pyx", line 540, in fiona.ogrext.Session.startFile "fiona/_shim.pyx", line 81, in fiona._shim.gdal_open_vector
1 Like

Yeah, I’ve messed with GDAL and the like in a previous job, not so fun.

Keep in mind that you can also specify a packages.txt file, to add system-level dependencies. Maybe start by installing GDAL on the image and see if that gets you somewhere:

Thanks Randy - I appreciate the response, and bonus points for not making me feel like a total idiot on here :slight_smile:
i really dig streamlit and hope i can do something helpful with it… it’s a great tool and an amazing step in the right direction!

1 Like

ok - i’ve been going through the packages.txt file stuff & could use some documentation there? if i need to add the repository to apt-get install gdal i’m not sure how to do that?

i definitely think i need gdal & more than that libspatialindex for analyzing geospatial data regardless…

i’ve used this repository to set up the back end for jupyter notebooks? any thoughts

Here’s an example packages.txt file:

I would start by removing the two lines that are there and instead putting gdal-bin on its own line and seeing what happens. In general, you should try to find things that are already binaries that can be installed by apt, I don’t think we currently make any functionality available for running make or other compilation steps.

After cloning your app, it appears that you don’t even need to install gdal…see my changes here:

It appears all you need to do is add pygeos to your requirements.txt file, and you can remove everything from your requires.txt (which will speed up deployment)

Here’s some documentation to hopefully help anyone else looking at geopandas and streamlit

1 Like