Error in value[[3L]](cond): Python virtual environment Directory can't be recognized after ShinyApp deployed

...I wrote a ShinyApp to display the results of python scripts by creating a python virtual environment, The Shiny code works well on my own computer, and it also can be deployed. But when I opened the url after the deployment, a error appeared as follow:


It shows that the python virtual environment folder I created is not what it is. But there was no error when I run it locally. Here is my part of code:

path <- "C:/Users/wdeng/Desktop/cases/case_AE/ShinyApp"
use_python(paste(path,'/myvenv/Scripts/python.exe', sep = ''))
use_virtualenv(paste(path,'/myvenv/',sep = ''), required = TRUE)
source_python(paste(path,"/AE_products_checks.py",sep = ''))
source_python(paste(path,"/doc2docx.py",sep = ''))
1 Like

See the Troubleshooting section of the documentation, in particular the part about relative versus absolute paths.

Also, shinyapps.io runs Linux, so use_python with a .exe is not going to work either.

Thanks so much, I have checked the Troubleshooting you mentioned in the reply and discarded applying use_python with a.exe, but the problem is still unresolved.

# use_python('myvenv/Scripts/python.exe')
use_virtualenv('venv', required = TRUE)
source_python("AE_products_checks.py")
source_python("doc2docx.py")
source("ui.R")
source('sever.R')
use_virtualenv('venv', required = TRUE)
source_python("AE_products_checks.py")
source_python("doc2docx.py")
source("ui.R")
source('sever.R')

The absolute directory has been changed into relative one, and the whole project works well in the local computer.

You need to make the virtualenv in shinyapps.io before you can use it.

I'm not sure what you mean by making the virtualenv in shinyapps.io, actually, I have bundled all required files when I deployed the app. The following action is what I have done before using it.!
1544496144(1)

Uploading your virtualenv is not likely to result in success either, since there is likely compiled code that works on whatever you are running locally, e.g. Windows, that will not work on shinyapps.io which runs Linux.

There is work underway in the rsconnect package to capture Python packages. Once that is released, there will need to be work on shinyapps.io to install them.

In the meantime, you will need to create the virtualenv and install the packages in the code that you deploy to shinyapps.io.

Thank you so much for all your clarifying and spending time helping me figure out where my problems locate .

1 Like

Hi, I have transplanted my project to Ubuntu virtual machine and configured the python virtual environment in it, but when i deploy it to shinyapp.io, i got the error as follow:

You should not need to translate your project to Ubuntu.
What you need to do is create the virtualenv from within the code you deploy, so that it is recreated in shinyapps.io. You should not be uploading the venv from your local machine.

Actually, I don't understand how to create the virtualenv within the code , could you please give me some instructions or some blogs? Thank you so much ahead.

I would start off at the reticulate site, and then post to the Community with appropriate tags, e.g. "reticulate" and "python", if you have specific questions that aren't covered by the package documentation. You could also open a Github issue.

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