Shiny App : Keras/tensorflow Problem

Have been playing around with dogs and cats data set. I successfully built a Keras Classification CNN. So far so good.
Then I created a shiny app.... and it runs ok, locally!
When I try to publish the app (, it seems that everything goes well. Though, when I open the deployed app I receive this:

I have to say that I am puzzled by the this message. I believe that it has something to do with path and/or with the environments (or not!), but can't find a solution.

Below the app code


model <- load_model_hdf5("dog_cat_class_model.h5")

ui <- fluidPage(
    titlePanel("Hello dear user"),
            fileInput("image_path", label = "Input a JPEG image")
        # Main panel for displaying outputs ----
            # Output: Histogram ----
            textOutput(outputId = "prediction"),
            plotOutput(outputId = "image")

server <- function(input, output) {
    image <- reactive({
    output$prediction <- renderText({
        image_new <- req(input$image_path$datapath)%>%
            image_load(.,target_size = c(150, 150))
        image_new_array <- image_to_array(image_new)
        ready_array <- array_reshape(image_new_array, c(1, 150, 150, 3))
        image_new_gen <- image_data_generator(rescale = 1/255)
        image_new_generator = flow_images_from_data(
            generator = image_new_gen,
            batch_size = 1)
        preds <- predict_generator(model,
        paste0("The predicted prob of being a dog is ", pred_prob,"%" )
    output$image <- renderPlot({

shinyApp(ui, server)

Thank You

You need to set up your virtual invironment properly to let know that you are using python. Did you add the Rprofile file with all the settings to your app?

Have a look at this example app and tutorial:

What your could do is clone the repository and see if you are able to deploy the example app to If it works simply replace the code in the App file with your own.

1 Like

Hello @noveld thanks for your reply,
I was not aware of the need to have the Rprofile. I am new to all the interface architecture, virtual environments etc... currently I am using a miniconda setup.

I tried your suggestion and publishing in that app was no problem. All good! So I created a virtual environment with reticulate, but when then try to publish my app, it seems that it lacks Keras and Tensorflow in that same environmnent. Then, from what I was able to get it seems that, it is not possible to do it in a windows machine (which I have). I got that here:

One step forward, but stucked again...

What are my options now?

Thanks again

If it works locally I don't think you have an issue with your installation of keras or tensorflow.

Now that you set your Rprofile did the error messages disappear? What does the log file show?

Another problem might be that the file path for your model is wrong. Did you put the file in the www folder? Maybe put a text file or image in the same location and see if it loads when you deploy to

Of course... sorry forgot to post the error.
The error that I am facing right now... When it runs the following line:

reticulate::virtualenv_install(virtualenv_dir, packages = PYTHON_DEPENDENCIES, ignore_installed=TRUE)

The verbose:

Traceback (most recent call last):
  File "C:\Users\PEDRO~1.DAV\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\PEDRO~1.DAV\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\PEDRO~1.DAV\DOCUME~1\VIRTUA~1\PYTHON~1\lib\site-packages\pip\", line 23, in <module>
    from pip._internal.cli.main import main as _main  # isort:skip # noqa
  File "C:\Users\PEDRO~1.DAV\DOCUME~1\VIRTUA~1\PYTHON~1\lib\site-packages\pip\_internal\cli\", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "C:\Users\PEDRO~1.DAV\DOCUME~1\VIRTUA~1\PYTHON~1\lib\site-packages\pip\_internal\cli\", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "C:\Users\PEDRO~1.DAV\DOCUME~1\VIRTUA~1\PYTHON~1\lib\site-packages\pip\_internal\cli\", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "C:\Users\PEDRO~1.DAV\DOCUME~1\VIRTUA~1\PYTHON~1\lib\site-packages\pip\_internal\cli\", line 25, in <module>
    from pip._internal.cli.progress_bars import BAR_TYPES
  File "C:\Users\PEDRO~1.DAV\DOCUME~1\VIRTUA~1\PYTHON~1\lib\site-packages\pip\_internal\cli\", line 12, in <module>
    from pip._internal.utils.logging import get_indentation
  File "C:\Users\PEDRO~1.DAV\DOCUME~1\VIRTUA~1\PYTHON~1\lib\site-packages\pip\_internal\utils\", line 18, in <module>
    from pip._internal.utils.misc import ensure_dir
  File "C:\Users\PEDRO~1.DAV\DOCUME~1\VIRTUA~1\PYTHON~1\lib\site-packages\pip\_internal\utils\", line 34, in <module>
    from pip._internal.locations import get_major_minor_version, site_packages, user_site
  File "C:\Users\PEDRO~1.DAV\DOCUME~1\VIRTUA~1\PYTHON~1\lib\site-packages\pip\_internal\", line 68, in <module>
    if platform.python_implementation().lower() == "pypy":
  File "C:\Users\PEDRO~1.DAV\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\", line 1267, in python_implementation
    return _sys_version()[0]
  File "C:\Users\PEDRO~1.DAV\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\", line 1225, in _sys_version
ValueError: failed to parse CPython sys.version: '3.6.10 |Anaconda, Inc.| (default, May  7 2020, 19:46:08) [MSC v.1916 64 bit (AMD64)]'
Error: Error installing package(s): "numpy"

I am sorry I don't really know what the problem could be. Maybe try to post your error log together with your Rprofile on Maybe you have more luck there finding an answer.

Sure @noveld. Thanks a lot for your help.
although I cannot fully achieve ultimate goal I believe that you really pointed me in the best direction.

It seems that this is another kind of problem I am facing now.

Thanks for your help,

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.