Streamlit with rpy2 and FactoMineR

Summary

I am trying to build an app by using python and rpy2. I read a .csv file (see below, table_mean_plain) and I would like to use FactoMineR and Streamlit. Unfortunately when I try to apply PCA to my dataset I receive an error message.

Steps to reproduce

Code snippet:

from rpy2.robjects.packages import importr, data
from rpy2.robjects.vectors import DataFrame
from rpy2.ipython.ggplot import image_png
import streamlit as st
import matplotlib.pyplot as plt
from rpy2 import robjects

import matplotlib.image as mpimg


utils = importr('utils')
corrplot = importr('corrplot')
FactoMineR = importr('FactoMineR')
factoextra = importr('factoextra')

my_datafile = 'table/plain/table_mean_plain.csv'

#my_data = utils.read_csv(my_datafile)

my_data = DataFrame.from_csvfile(my_datafile, row_names="X")
#rownames(my_data = my_data$X
#my_dataX = NULL

# Do PCA
# --------
res_pca = FactoMineR.PCA(my_data)

You can find the .csv file attached

Expected behavior:

No error message

Actual behavior:

I have an error message:

2022-10-26 13:47:51.679 R[write to console]:  Unable to create Cocoa Quartz window: NSWindow drag regions should only be invalidated on the Main Thread! (NSInternalInconsistencyException)
2022-10-25 17:08:05.231 Uncaught app exception
Traceback (most recent call last):
  File "/opt/anaconda3/envs/XX/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 562, in _run_script
    exec(code, module.__dict__)
  File "/Users/XX/Documents/XX/pages/4_Visualisations.py", line 69, in <module>
    res_pca = FactoMineR.PCA(my_data)
  File "/opt/anaconda3/envs/XX/lib/python3.9/site-packages/rpy2/robjects/functions.py", line 201, in __call__
    return (super(SignatureTranslatedFunction, self)
  File "/opt/anaconda3/envs/XX/lib/python3.9/site-packages/rpy2/robjects/functions.py", line 124, in __call__
    res = super(Function, self).__call__(*new_args, **new_kwargs)
  File "/opt/anaconda3/envs/XX/lib/python3.9/site-packages/rpy2/rinterface_lib/conversion.py", line 45, in _
    cdata = function(*args, **kwargs)
  File "/opt/anaconda3/envs/XX/lib/python3.9/site-packages/rpy2/rinterface.py", line 810, in __call__
    raise embedded.RRuntimeError(_rinterface._geterrmessage())
rpy2.rinterface_lib.embedded.RRuntimeError: Erreur dans (function (title, width, height, pointsize, family, antialias,  :
  impossible de créer le périphérique cible quartz(), le type fourni n'est peut-être pas supporté

Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentlyBuildingLayerTree), function NSViewSetCurrentlyBuildingLayerTreeForDisplay, file NSView.m, line 13477.
[9]    59974 illegal hardware instruction  streamlit run 1_Workbench.py

Debug info

  • Streamlit version: 1.13
  • Python version: 3.9.13
  • Using Conda
  • OS version: Mac

Requirements file

The corresponding dataset

,logistic-regression,svm-linear,svm-rbf,Gnb,decision-tree,random-forest,XGBoost,MLP,Ensemble,GEV,iForest,DevNet
news,0.827,0.566,0.724,0.681,0.687,0.852,0.865,0.859,0.866,0.87,0.497,0.666
telE,0.761,0.552,0.623,0.756,0.86,0.944,0.957,0.915,0.95,0.941,0.399,0.717
bank,0.832,0.62,0.772,0.817,0.687,0.848,0.841,0.848,0.855,0.873,0.625,0.793
member,0.648,0.488,0.514,0.625,0.574,0.696,0.695,0.669,0.707,0.667,0.545,0.598
dsn,0.735,0.708,0.785,0.707,0.761,0.884,0.897,0.754,0.884,0.766,0.568,0.661
mobile,0.889,0.432,0.393,0.842,0.776,0.9,0.906,0.9,0.908,0.907,0.7,0.852
campaign,0.907,0.543,0.668,0.809,0.709,0.928,0.933,0.923,0.935,0.924,0.65,0.832
HR,0.85,0.766,0.841,0.762,0.615,0.809,0.797,0.825,0.838,0.827,0.589,0.72
sato,0.794,0.747,0.8,0.729,0.651,0.808,0.809,0.799,0.825,0.82,0.5,0.739
uci,0.854,0.586,0.897,0.859,0.818,0.901,0.905,0.847,0.913,0.91,0.663,0.793
TelC,0.844,0.632,0.797,0.814,0.658,0.819,0.825,0.842,0.841,0.85,0.295,0.784
median_AUC,0.832,0.586,0.772,0.762,0.687,0.852,0.866,0.847,0.866,0.87,0.568,0.739
Rank,5.67,10.67,7.5,8.08,9.0,4.0,3.25,5.0,1.83,2.67,11.42,8.92