-3

We are building a User Interface APP (predicting a continuous variable through a machine learning model) through R Shiny. Since we built the machine learning model in Python3 sklearn module, we hope that we could write python codes in R Shiny to call that model and corresponding functions.

We used R-package "reticulate" to create virtual python environment where it would save python packages, and through which we could call python3 functions.

We created the virtual environment using the following line of code (the function in R package "reticulate")

use_virtualenv("env", required = TRUE)

Where we indeed have the following directory "env/bin" in which there are python and python3 to execute.

The Shiny APP worked perfectly locally. HOWEVER, when we made attempts to publish, it gave the following error (please see picture) (after the APP was successfully deployed and on shinyapps.io, it said the APP was running).

The issue was "Error 126", which denied the permission for our APP to access the virtual environment. This issue had no previous (similar) case on Stackoverflow, and therefore we spent a long time to debug (issue not resolved).

If anyone knows how to solve this problem, would it be possible for you to kindly mark your solution tips below? (We hope your solution would not modify our basic layout, i.e. "calling python-made model in Shiny and publish through Shiny") We really appreciate your efforts to help us out!

Thank you so much!

2 Answers2

0

Could you share the code where actual call to python script is being made? is it a python module function that you are calling from Rshiny? what does the python module/function do and return? I have used reticulate inside shiny to call Python scripts and it works fine. Didn't require to set the environment. Just provide the source to python script and call it like any other R function.

jacob mathew
  • 143
  • 1
  • 11
0

If you're trying to deploy to shinyapps.io, you may need to set the RETICULATE_PYTHON env variable so that reticulate uses the correct version of Python when running your app:

VIRTUALENV_NAME = 'env'
Sys.setenv(RETICULATE_PYTHON = paste0('/home/shiny/.virtualenvs/', 
                               VIRTUALENV_NAME, 
                               '/bin/python'))

Full example here demonstrates one method for configuring a Shiny + reticulate app so that it can easily run both locally and on shinyapps.io.

Rani Powers
  • 196
  • 3
  • 6