question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rpy2 does not work with streamlit

See original GitHub issue

Summary

One can not use the package Rpy2 to call R function from within streamlit. Importing the rpy2 package crashes with an “ValueError: signal only works in main thread”

Steps to reproduce

Code snippet:

import streamlit as st
import rpy2.robjects as robjects

Expected behavior:

Importing the rpy2 package

Actual behavior:

Importing the rpy2 package crashes with an “ValueError: signal only works in main thread”

Is this a regression?

Do not know, never tried before.

Debug info

  • Streamlit version: 0.74.1
  • Python version: (3.8
  • Using Conda
  • OS version: Ubuntu 20
  • Browser version: Chrome 87.0.4280.141

Additional information

I was told to open this issue in the discussion forum, see https://discuss.streamlit.io/t/using-rpy2-within-streamlit/8812

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lgautiercommented, Aug 27, 2021

Otherwise I don’t think that there is any reason R would (or could) keep running after the Python process ends. R is embedded in the Python process. Think of it as a C library called from the Python process.

1reaction
lgautiercommented, Aug 27, 2021

I am not familiar enough with Streamlit, but I suspect that importing streamlit has side effects (beyond loading Python modules and packages). One of them is that one or several threads are created and the rest of the code in your Python module (that is source file) will be evaluated by the thread(s).

If the case, changing the order of imports might clear the warning message you are seeing. Try changing

import streamlit as st
import rpy2.robjects as robjects

to

import rpy2.robjects as robjects
import streamlit as st
Read more comments on GitHub >

github_iconTop Results From Across the Web

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...
Read more >
Using rpy2 with streamlit - python - Stack Overflow
I am trying to build an app by using python and rpy2. ... When I use the code in Jupyter notebook it is...
Read more >
How to run R and Python together in a Streamlit app - YouTube
Your browser can't play this video. Learn more. Switch camera.
Read more >
How to Deploy Streamlit Apps on RStudio Connect - R-bloggers
Streamlit is a fairly new framework for data science web applications that has taken the data science world by storm. It allows creating ......
Read more >
Python application deployment with RStudio Connect: Streamlit
RStudio Connect is a platform which is well known for providing the ability to deploy and share R applications such as Shiny apps...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found