jupyterhub / jupyter-rsession-proxy

Jupyter extensions for running an RStudio rsession proxy
BSD 3-Clause "New" or "Revised" License
118 stars 87 forks source link

Geospatial packages cannot be imported to Rstudio sessions #136

Closed angelosnm closed 1 year ago

angelosnm commented 1 year ago

It is not an actual issue with this project but one related to GDAL and the general difficulty of it to be intergrated to a system and I open this issue in case anyone faced such issues.

I have installed some geospatial R packages in my notebook such as r-raster, r-terra, r-sp and others using "conda install". Those work fine inside pure Jupyter environment but when one tries to import them from Rstudio environment the below comes up:

image

It is clear that GDAL which is installed under the hood cannot recognize the runtime as conda one.

P.S: I have installed other packages (not related with GDAL) with the same way and those can be loaded normally into Rstudio as expected.

welcome[bot] commented 1 year ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

angelosnm commented 1 year ago

I found the solution to the above by adding the commands below from section "System tweaks for Rstudio integration with geospatial packages" in my Dockerfile! (I am running jupyter/datascience-notebook:ubuntu-20.04 as a base image)

Rstudio installation

RUN cd /tmp && \ wget https://download2.rstudio.org/server/bionic/amd64/rstudio-server-2022.07.1-554-amd64.deb && \ gdebi -n rstudio-server-2022.07.1-554-amd64.deb

ENV PATH=$PATH:/usr/lib/rstudio-server/bin

Switching to default "jovyan" user account to install jupyterlab and conda extensions & packages

USER jovyan

R Geospatial packages installation

RUN conda install -c conda-forge gdal r-rgdal r-raster r-terra r-sp r-sf

System tweaks for Rstudio integration with geospatial packages

RUN sudo rm /usr/lib/x86_64-linux-gnu/libstdc++.so.6 RUN sudo ln -s /opt/conda/lib/libstdc++.so.6.0.30 /usr/lib/x86_64-linux-gnu/libstdc++.so.6

Rstudio Jupyter plugin installation

RUN python3 -m pip install jupyter-rsession-proxy RUN cd /tmp/ && \ git clone --depth 1 https://github.com/jupyterhub/jupyter-server-proxy && \ cd jupyter-server-proxy/jupyterlab-server-proxy && \ npm install && npm run build && jupyter labextension link . && \ npm run build && jupyter lab build