Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pre-install Python dependencies for reticulated project? #1052

Open
TengMCing opened this issue Mar 13, 2024 · 2 comments
Open

How to pre-install Python dependencies for reticulated project? #1052

TengMCing opened this issue Mar 13, 2024 · 2 comments

Comments

@TengMCing
Copy link

Hi,

I have successfully deployed a reticulated project with the following app.R, but when I include tensorflow in py_install(), the app will take too long to start up because of the installation and shinyapps.io will shut it down.

library(shiny)
library(ggplot2)

reticulate::py_install(c("numpy", "Pillow"),
                       envname = "r-web_interface",
                       method = c("virtualenv"))
reticulate::use_virtualenv("r-web_interface")

PIL <- reticulate::import('PIL')
np <- reticulate::import("numpy")

server <- function(input, output) { 
  output$py_config <- renderText(capture.output(reticulate::py_config()))
}

ui <- fluidPage(textOutput('py_config'))

shinyApp(ui, server)

Is there a way to pre-install all these Python dependencies at build time?

It seems like there is a solution provided at https://solutions.posit.co/write-code/reticulate/, but when I deploy the app with the RStudio button, the published app will ignore all the Python dependencies (I have downloaded and checked the manifest.json file of the deployed app).

And if I use rsconnect::writeManifest() first to generate manifest.json and requirements.txt, then deploy the app with the rsconnect cli - rsconnect deploy manifest manifest.json, the deployed app will not be able to find a Python interpreter at .venv/bin/python.

@GitHunter0
Copy link

GitHunter0 commented Aug 27, 2024

Hey folks @aronatkins , @jjallaire , @hadley , being able to install python packages at building time (passing a requirements.txt or a conda environment.yml) is indispensable in my opinion since R lacks essential AI, deep learning and even image packages like kaleido ...

An alternative would be to Dockerize the app to be able to install whatever you want:

  • Then you could host on your own cloud server (EC2 for example) but this is not a scalable solution.

  • Or to scale you could deploy on Google Cloud Run or AWS App Runner but it will not work properly because Shiny apps are stateful applications which require sticky sessions.

  • Other option would be to deploy using Kubernetes with appropriate Load Balancer configuration, which requires expert knowledge.

Therefore, the only simple viable solution today to deploy Shiny apps with reasonable scalability would be shinyapps.io (or Posit Connect but it is expensive and more suitable for larger enterprises). But since it does not allow python packages installation, what else can we do?

With that in mind, I believe most developers will not use Shiny (despite being a brilliant framework) because of these limitations. And our R community will continue to lose ground.

What are your thoughts about this?

Thank you

@MatthiasReccius
Copy link

I want to push this issue. I have spent several days and tried a plethora of workarounds trying to avoid having to install python packages at runtime. Without success. It appears that shinyapps.io does not cache venvs between session and rsconnect and shinyapps, in general, are doing their best to ignore them when they are in the uploaded files.

This must be an issue for many people since Python offers all kinds functionalities that native R does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants