how to specify python when using reticulate

I've just deploy a flexdashboard "successfully" yet the app doesn't work: it links to a page with just "not found" on it. Here's the full app upload transcript:

Preparing to deploy application...DONE
Uploading bundle for application: 857453...DONE
Deploying bundle: 2005872 for application: 857453 ...
Waiting for task: 604267183
building: Processing bundle: 2005872
building: Parsing manifest
building: Building image: 2108212
building: Installing system dependencies
building: Fetching packages
building: Building package: reticulate
building: Building package: tensorflow
building: Building package: keras
building: Installing packages
building: Installing files
building: Pushing image: 2108212
deploying: Starting instances
rollforward: Activating new instances
success: Stopping old instances
Application successfully deployed to https://xxxx.shinyapps.io/xxxx/
Warning messages:
1: invalid uid value replaced by that for user 'nobody'
2: invalid gid value replaced by that for user 'nobody'

I thought the error had to do with the warning messages above but i've checked the logs and the point of failure seems to be with reticulate:

warning: using reticulate but python was not specified; will use python at /usr/bin/python  
Did you forget to set the RETICULATE_PYTHON environment variable in your .Rprofile before publishing?

I checked what python installation my local reticulate uses with:

library(reticulate)
py_config()

and i edited the .RProfile to match it:

Sys.setenv(RETICULATE_PYTHON = "/Users/xxxx/anaconda3/envs/r-tensorflow/bin/python")

but it's still producing the same "not found" error when i deploy on shinyio. Any idea how to fix this?

Hi @chrisjacques13! I'm not sure if this will fix your problem, but reticulate actually has a dedicated function for specifying a version of python inside a conda environment. Take a look at use_condaenv():

https://rstudio.github.io/reticulate/reference/use_python.html

If you use this, you can specify the name of the environment and reticulate will just look for conda in the PATH (or you can specify conda's location if it's not in a typical location).

Does that work for you?

EDIT: sorry, I missed the part where you said that you're getting the error when you deploy on shinyapps.io. If you're publishing there, the python configuration will be different—you don't be able to rely on a conda environment that's somewhere in your user folder!

reticulate should just work out-of-the-box on shinyapps.io, but you might need to write some code for the app to check whether it's running locally or on shinyapps.io in order to decide whether it should use conda.

how would you do that...? do you have an example i could use?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.