I am creating an app in Shiny using R. I have a model in python that I am using in the app so I use the reticulate
package to run it and a virtual environment in the same folder as the app to access python3
. It works great locally, but once I deploy it I get an error in the logs that says
venv/bin/python: Permission denied
(venv is my virtual env).
I have tried adding an .Rprofile
file (to the folder with the app) that includes source venv/bin/activate
. Also, in case it is helpful, the Python component uses the keras
package. I have also downloaded all of the necessary packages into my virtual environment.
I also ran use_python("venv/bin/python", required = TRUE)
instead of reticulate::use_virtualenv("venv", required = TRUE)
which also works locally, but I get the same error described above once I deploy it.
This has been solved! The solution was to create the virtual environment and download necessary packages inside the R code file. If others have the same problem, here is the relevant code to set up the python virtual environment to be able to deploy to shinyapps.io:
virtualenv_create(envname = "python_environment", python= "python3")
virtualenv_install("python_environment", packages = c('keras', 'pandas','numpy','scipy','scikit-learn', 'tensorflow'))
reticulate::use_virtualenv("python_environment", required = TRUE)
For clarity, the specific packages are just what my python code needed.
Also, you may need to run (and then comment out for deployment) the following line to use an older version of rsconnect if you get an error that says: reticulate is in use, but python was not specified
devtools::install_github("rstudio/rsconnect", ref='737cd48')