0

I am trying to publish a Shiny application that uses a module that I wrote. This Python module uses selenium, pandas, urllib3, time, and re. First, I tried to create a virtualenv and publish the virtualenv along with the app. I kept getting a ModuleNotFoundError for selenium (selenium is the first library I import). Then after some reading I figured out that I need to create a virtual environment within shinyapps. So, my code at the beginning of my app now looks like this:

library(shiny)
library(tidyverse)
library(DescTools)
library(lubridate)
library(googlesheets4)

# Import python module scrapeinsolvencyinsider.py
reticulate::virtualenv_create(envname="statcanEnv", python="python3", version=3.8)
reticulate::virtualenv_install("statcanEnv", packages=c("pandas", "selenium", "urllib3"))
reticulate::use_virtualenv("statcanEnv", required=TRUE)
sii <- reticulate::import("scrapeinsolvencyinsider")

Again I get the ModuleNotFoundError:ModuleNotFoundError

My question is, how can I deploy a Shiny app that uses Python modules?

Also, I will need a way of also installing ChromeDriver on shinyapps.io as well.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
BigBossRob
  • 75
  • 5

1 Answers1

2

I've found a solutions, thanks to this post which refers to this link: https://github.com/ranikay/shiny-reticulate-app/blob/master/.Rprofile.

I configured my .Rprofile, only changing the environment name and the python version. Then I saved it and published it along with my app. I also made some changes to my app:

library(shiny)
library(tidyverse)
library(DescTools)
library(lubridate)
library(googlesheets4)

# Import python module scrapeinsolvencyinsider.py
reticulate::virtualenv_create(envname="statcanEnv", packages=c("pandas", "selenium", "urllib3", "chromedriver-py==91.0.4472.19"))
sii <- reticulate::import("scrapeinsolvencyinsider")

Now my app deploys as expected: app

BigBossRob
  • 75
  • 5