Using rpy2 within Streamlit

Hello,

I’m trying to use the rpy2 package to call R functions from within Streamlit, but it does not even manage to import the rpy2 package but crashes with an
“ValueError: signal only works in main thread”

    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))

Here is the minimal example:
import streamlit as st import rpy2.robjects as robjects

Does anyone know how to solve this?
Thank you very much.

Hi @christophBoerlin, welcome to the Streamlit community!

I suspect the issue here might be that rpy2 might want to run from the main Python thread, and Streamlit executes the user script on a separate thread.

Would you mind opening a GitHub issue for this so that we don’t lose track?

1 Like

Just for closure, here’s the GH issue: Rpy2 does not work with streamlit · Issue #2618 · streamlit/streamlit · GitHub

Did some rpy2 in Streamlit today and at first glance it works, still need to confirm the embedded R gets closed correctly.

1 Like