Closed andrewelamb closed 2 years ago
All: I'm interested in how supporting automated deployment to ShinyApps affects local builds and how to make both as easy as possible. If performing a local build is too cumbersome, let's talk about how to make it more streamlined.
@brucehoff I think most folks at Sage are using miniconda as opposed to python virtual envs. We were up to this point for projectlive. I don't have any strong preferences.
@andrewelamb One option is to add a Dockerfile to this repo' that takes care of setting up the virtual env', as well as all other dependencies, required for a local build. One would then simply run the docker build
and docker run
commands to build and launch the app' locally.
@andrewelamb Thanks! I have now created a python virtual env and installed synapseclient. But when I try to run projectLive locally, I am getting the following error:
Error : Python module synapseclient was not found.
Detected Python configuration:
Error in py_call_impl(callable, dots$args, dots$keywords) :
Evaluation error: Unable to access object (object is from previous session and is now invalid).
I confirmed that synapseclient is installed in my python virtual env. Any idea why projectLive cant find it?
@jaybee84 https://community.rstudio.com/t/error-in-py-call-impl-unable-to-access-object/37147/3
You may need to restart rstudio?
Otherwise I would try starting with a clean clone of the repo. It maybe conflicts with the old conda env?
In case it's useful, reticulate::py_discover_config
can be helpful for figuring out what python reticulate happens to be using. When you call use_conda
or use_virtualenv
without force = T
, reticulate will silently fall back on a different python if it can't find the one you are requesting.
Sorry, I meant required = T
, not force = T
.
Thanks @allaway .. this may be happening here:
It seems that the virtual_env python
is found but reticulate
is falling back on the default usr/bin/python
reticulate::py_config()
python: /usr/bin/python
libpython: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib
pythonhome: /System/Library/Frameworks/Python.framework/Versions/2.7:/System/Library/Frameworks/Python.framework/Versions/2.7
version: 2.7.16 (default, Jun 18 2021, 03:23:53) [GCC Apple LLVM 12.0.5 (clang-1205.0.19.59.6) [+internal-os, ptrauth-isa=deploy
numpy: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
numpy_version: 1.8.0
synapseclient: [NOT FOUND]
python versions found:
/usr/bin/python3
/usr/bin/python
/Users/jineta/virtual_env/bin/python
@andrewelamb I think the reticulate config is being called through the projectlive_modules
. Would you like to add the code snippet in there?
@jaybee84 I'm unclear on what you mean.
The called module is here.
Please take a look here: https://github.com/Sage-Bionetworks/projectlive-modules/pull/53
I could not test it locally, but wanted to suggest a solution close to what I was referring to earlier. For some reason that I dont fully understand yet, adding this snippet to zzz.R
which calls reticulate
to make synapseclient
available to the app did not work.
@jaybee84 , when I was poking around earlier I saw this was in globals.R
in this repo, I think you might want to edit this one instead: https://github.com/Sage-Bionetworks/projectLive_NF/blob/a83f12753525c4b28c8fe88a81f1f15f0f4cbbd1/R/global.R#L6
@jaybee84 That function you modified isn't used by the app, so changing it won't help.
The code for using reticulate and login is in these files: R/zzz.R R/global.R R/app_server.R
Thanks @allaway and @andrewelamb ..
I edited both R/zzz.R
and R/global.R
... neither helped..
I dont see reticulate being called in R/app_server.R
...
It's being called in R/zzz.R:
`### This file loads synapseclient and makes it globally available to the app
synapse <- NULL
.onLoad <- function(libname, pkgname) { .GlobalEnv$synapseclient <- reticulate::import("synapseclient", delay_load = TRUE) }`
Yes.. This is the first place I tried to modify (see comment here) .. unfortunately it did not work
@allaway have you got this to work?
I have not tried...figured maybe too many cooks :)
@jaybee84 let me know if you want me to give it a shot on my laptop
@allaway Sure, happy to have you try..
Well you know (n = 2) > (n = 1)
@jaybee84 Look here.
"I observed that neither the technique "use_python('path')" nor the tactic of Sys.setenv(RETICULATE_PYTHON = 'path') in .RProfile worked for me (of course I am sure it must have worked for others.)
In any case the line at terminal,
which -a python python3 did produce two paths to choose from (one for python2 and one for python3 installed on my mac), **so then I was able to create a ".Renviron" file in my home directory with this single line in it:
RETICULATE_PYTHON="/usr/local/bin/python3"** After I restarted RStudio, library(reticulate) activates the desired python3, and repl_python() opens a python3 interactive window, etc. etc."
I got it to work on my end... The reason was the filepath.
In R/global.R
adding required = TRUE
was not working because the path called by reticulate::use_virtualenv(file.path(getwd(),venv_name))
was not routing to the correct env. It assumes that the virtual env is loaded in the current working directory which in my case it is not..
Once I hard coded the right path to the virtual_env
.. it worked on my end
Can you show me the exact modifcation you made?
In R/global.R
:
replaced
reticulate::use_virtualenv(file.path(getwd(),venv_name))
with
reticulate::use_virtualenv("/Users/jineta/virtual_env", required = TRUE)
Note:
reticulate::use_virtualenv(file.path(getwd(),venv_name), required = TRUE)
does not find the right path
@jaybee84 what directory were you in when you ran these commands:
python3 -m venv virtual_env
chmod 755 virtual_env/bin/activate
source virtual_env/bin/activate
pip3 install synapseclient
If you were in the directory with the app , ie. dir1/dir2/projectLive_NF, it should have created the virtualenv there
Aha.. I was not in the projectLive_NF dir when I ran the commands to create the virtual_env. I generally create virtual envs in my home dir and did the same in this case too
@jaybee84 Hopefully that's the issue :) Could you try that again and change the code back to
reticulate::use_virtualenv(file.path(getwd(),venv_name), required = TRUE)
and see if that works?
yep.. that worked.. :)
Great! Let's make sure it's working for @allaway before accpeting the PR.
Can someone share the oauth_config.yaml details? I don't have the client id or secret.
They are in last pass under "Synapse Shiny local oauth client config" make sure everything is quoted like:
client_id: "0000" client_secret: "xxxxx" app_url: "http://127.0.0.1:8100"
Oh, I see, there is a generic config that folks are using for all apps running local. Interesting!
Anyway, I made the change to reticulate::use_virtualenv(file.path(getwd(),venv_name), required = T)
and the app worked fine for me. Thanks!
Yeah it's an OAuth thing, i know enough about ti to get it to work.
@jaybee84 @allaway. @brucehoff made some changes to how the app works to get it so that it deploys. This is the cause of the errors you are seeing here and here.
Two things you'll need to do, run the following code to create a python virtual env(as opposed to a conda env):
You will also need to move "inst/oauth_config.yaml" to "oauth_config.yaml".