I'm having trouble deploying a Shiny app to shinyapps.io that uses Python via the reticulate package. The app runs perfectly locally — the Python environment is detected and everything works as expected. But when I deploy it, I get the following error:
[Insert key error message here, e.g., “Warning: The reticulate package is installed but no Python environment is available...”]
This is my .Rprofile:
Sys.setenv(RETICULATE_PYTHON = "/Users/kivanov/.virtualenvs/r-reticulate/bin/python")
Here’s some context:
Python version: 3.11.8
R version: 4.5.0
.Rprofile is in the same folder as app.R and the dataset files
I'd really appreciate any tips or guidance to get this working. Thank you so much!
The error you're getting says that there is no Python installation. The server that shinyapps.io uses to host your app doesn't have python installed, which makes sense because your R app is being hosted on a server that is designed for R apps.
Reticulate is something of a special case because unlike almost all other R packages, it uses R to call functions from another programming language. This works fine on your own laptop because you must have a python environment installed (some operating systems even come with it by default).
You could write the app in Shiny Python and natively use whatever Python functionality you need, or find an R equivalent to the code you're calling with Reticulate.
You most likely want to avoid creating RETICULATE_PYTHON env. variable in shinyapps instance that points to a virtualenv location that can't exist there.
So try deploying without bundling .Rprofile file. Or if you have something else in .Rprofile that as well, try to reorganize project's env. vars so your local RETICULATE_PYTHON would not not end up in shinyapps instance, for example move RETICULATE_PYTHON = ... to project's .Renviron while making sure the file is not bundled.
reticulate now supports & promotes a different approach, declaring Python requirements through py_require() calls:
This also works when deploying apps to shinyapps.io . While there's rsconnect issue that suggests to disable rsconnect.python.enabled option prior deploying - Using reticulate with uv python · Issue #1143 · rstudio/rsconnect · GitHub - I had no real issues leaving it as-is, just few related warnings in logs. Though uv environment is rebuilt every time app wakes from sleep, so it's probably not optimal for projects with many and / or large dependencies.
A simple toy example that declares Python version and package requirements through py_require():