I am trying to deploy shiny app, that uses reticulate and keras packages. I do not have any problem to run it locally, but real troubles appear, when I try to deploy it to shinyapps/io. My app.r file is as follows:
virtualenv_dir = Sys.getenv("VIRTUALENV_NAME")
python_path = Sys.getenv("PYTHON_PATH")
reticulate::virtualenv_create(envname = virtualenv_dir, python = python_path)
reticulate::virtualenv_install(virtualenv_dir, packages = c("numpy", "h5py", "scipy", "scikit-image", "pyyaml", "pillow"), ignore_installed = TRUE)
reticulate::use_virtualenv(virtualenv = virtualenv_dir)
library(shiny)
library(keras)
library(reticulate)
library(magick)
library(raster)
library(EBImage)
library(rdrop2)
library(plotly)
np <- import("numpy", convert=FALSE)
ndi <- import("scipy.ndimage", convert=FALSE)
segment <- import("skimage.segmentation", convert=FALSE)
feature <- import("skimage.feature", convert=FALSE)
model = load_model_hdf5("model_v02122020.h5")
ui <-
tagList(
fluidPage(
sidebarLayout(sidebarPanel(
fileInput("upload", "Choose a file", accept = c('image/png', 'image/jpeg')),
actionButton('click', 'Start')
),
mainPanel(
tabsetPanel(type="tabs",
tabPanel("Input image", plotOutput("InputImagePlot", height="100%")),
tabPanel("Output image", plotOutput("OutputImagePlot", height="100%")),
)
)
)
)
)
server <-
function(input, output, session) {
observeEvent(input$click, {
## some code for image processing
})
}
shinyApp(ui = ui, server = server)
My .Rprofile file is in accordance with this source: shiny-reticulate-app/.Rprofile at master · ranikay/shiny-reticulate-app · GitHub).
The deployment process seems to run completely according to R log. The error I get from the bottom of the log:
Error in value[[3L]]: Installation of TensorFlow not found.
Python environments searched for 'tensorflow' package:
You can install TensorFlow using the install_tensorflow() function.
/home/shiny/.virtualenvs/virt_tf/bin/python3
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
When I try to include tensorflow
into the list of packages required to be installed into my virtualenvironment I get the following error message:
Downloading tensorflow-2.3.1-cp35-cp35m-manylinux2010_x86_64.whl (320.4 MB)
Collecting tensorflow
Killed
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
Error in value[[3L]]:
Error installing package(s): 'numpy', 'h5py', 'scipy', 'scikit-image', 'pyyaml', 'pillow', 'tensorflow'
Execution halted
Out of memory!
As far as I understand, shinyapps/io pushes me to install tensorflow package into virtualenvironment. But tensorflow cannot be installed, because it is too heavy. However, I guess, tensorflow should be in the list of available packages, and can be called with library()
or request()
commands, isn't it so?. But how to force using it?