Intermittent app loading failure on shinyapps.io

Hi All,

We recently deployed an app on shinyapps io with "basic" tier support (mostly to facilitate multiple instances of our application). Unfortunately, despite successful deployment and initial loading of the application at its shinyapps io domain, it now intermittently fails to load with the following error:

OSError: [Errno 26] Text file busy: '/home/shiny/.virtualenvs/intervista/bin/python3'

Interestingly, refreshing the page allows the app to load normally, so I'm trying to figure out how to troubleshoot this issue... I've already tried toggling the package caching setting, but this had no effect.

For more background, our app leverages both R and Python, so I have followed the general advice from this end-to-end tutorial for using Shiny and reticulate to create apps with R and Python 3. This includes adding the following lines to my app.R file to create a virtual environment and install the Python packages that I need on the shinyapps io server/machine infrastructure:

# make a virtualenv
reticulate::virtualenv_create(envname = 'intervista', python = '/usr/bin/python3')

# install Python packages
reticulate::virtualenv_install(envname= 'intervista', packages=c('requests', 'pandas', 'biopython==1.76'))

# use intervista environment
reticulate::use_virtualenv("intervista", required=TRUE)

Additionally, I added the below text as an .Rprofile file (copied from the aforementioned tutorial) that specifies which Python version to use

# This file configures the virtualenv and Python paths differently depending on
# the environment the app is running in (local vs remote server).
# Edit this name if desired when starting a new app

VIRTUALENV_NAME = 'intervista'

# ------------------------- Settings (Do not edit) -------------------------- #

if (Sys.info()[['user']] == 'shiny'){

# Running on shinyapps.io
Sys.setenv(PYTHON_PATH = 'python3')
Sys.setenv(VIRTUALENV_NAME = VIRTUALENV_NAME) # Installs into default shiny virtualenvs dir
Sys.setenv(RETICULATE_PYTHON = paste0('/home/shiny/.virtualenvs/', VIRTUALENV_NAME, '/bin/python3.5'))

} else if (Sys.info()[['user']] == 'rstudio-connect'){

# Running on remote server
Sys.setenv(PYTHON_PATH = '/opt/python/3.7.6/bin/python')
Sys.setenv(VIRTUALENV_NAME = paste0(VIRTUALENV_NAME, '/')) # include '/' => installs into rstudio-connect/apps/
Sys.setenv(RETICULATE_PYTHON = paste0(VIRTUALENV_NAME, '/bin/python3'))

} else {

# Running locally
options(shiny.port = 7450)
Sys.setenv(PYTHON_PATH = 'python3')
Sys.setenv(VIRTUALENV_NAME = VIRTUALENV_NAME) # exclude '/' => installs into ~/.virtualenvs/

# RETICULATE_PYTHON is not required locally, RStudio infers it based on the ~/.virtualenvs path

}

Any ideas on what might be going on here would be greatly appreciated!!

Thanks!

1 Like