Shiny app with a TensorFlow model: Argument 1 is not a vector

Hi there,

I have asked a similar post about this - which is still pending, however - I have fixed the Tensorflow errors which were being thrown before, using the below link:

Tensorflow related error when deploying shiny app on - shiny / - RStudio Community

This is the code in my app.R file

library (png)

reticulate::virtualenv_create("myenv", python="/usr/bin/python3")
reticulate::use_virtualenv("myenv", required=TRUE)

if (!is_keras_available()) {
  install_keras(method="virtualenv", envname="myenv")
  reticulate::use_virtualenv("myenv", required=TRUE)

model <- load_model_tf("www/bird_mod/")
target_size <- c(224,224,3)

ui <- fluidPage(
  #(1) Header

  dashboardHeader(title=tags$h1("cagedbirdID",style="font-size: 120%; font-weight: bold; color: white"),
                  titleWidth = 350,
                  tags$li(class = "dropdown"),
                  dropdownMenu(type = "notifications", icon = icon("question-circle", "fa-1x"), badgeStatus = NULL,
                               tags$li(a(href = "",
                                         target = "_blank",
                                         tagAppendAttributes(icon("icon-circle"), class = "info"),
                                         "Created by Sicily Fiennes"))
  #(2) Sidebar
    fileInput("input_image","File" ,accept = c('.jpg','.jpeg')), #,'.png') 
    tags$p("Upload the image here.")
  #(3) Body
    tags$br(),tags$p("1. Take a picture of a bird."),
    tags$p("2. Crop image so that bird fills out most of the image."),
    tags$p("3. Upload image with menu on the left."),
      column(h4("Image:"),imageOutput("output_image"), width=6),
      column(h4("Prediction:"),tags$br(),textOutput("warntext",), tags$br(),
             tags$p("This bird is most likely a:"),tableOutput("text"),width=6)

server <- function(input, output) {
  image <- reactive({image_load(input$input_image$datapath, target_size = target_size[1:2])})
  prediction <- reactive({
    x <- image_to_array(image())
    x <- array_reshape(x, c(1, dim(x)))
    x <- x/255
    pred <- model %>% predict(x)
    pred <- data.frame("Bird" = label_list, "Confidence" = t(pred))
    pred <- pred[order(pred$Prediction, decreasing=T),][1:5,]
    pred$Prediction <- sprintf("%.2f %%", 100*pred$Prediction)
  output$text <- renderTable({
  output$warntext <- renderText({
    if(as.numeric(substr(prediction()[1,2],1,4)) >= 30){return(NULL)}
    warntext <- "Warning: I am not sure about this bird!"
  output$output_image <- renderImage({
    outfile <- input$input_image$datapath
    contentType <- input$input_image$type
    list(src = outfile,
         width = 400)
  }, deleteFile = TRUE)

shinyApp(ui, server)

I think this has something to do with the server section of my code because I can load Tensorflow fine now, after making the suggested edits to the .Rprofile file. There are also no absolute paths in the code, it is all relative paths. The app also works perfectly fine locally. The code was inspired from this post How to build your own image recognition app with R! [Part 2] – For-loops and piep kicks (

These were the logs for my Shiny app:

2021-09-08T12:35:13.508161+00:00 shinyapps[4599106]: Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
2021-09-08T12:35:13.626892+00:00 shinyapps[4599106]: Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
2021-09-08T12:35:13.623194+00:00 shinyapps[4599106]: Collecting pyasn1<0.5.0,>=0.4.6
2021-09-08T12:35:13.669680+00:00 shinyapps[4599106]: Collecting oauthlib>=3.0.0
2021-09-08T12:35:13.977908+00:00 shinyapps[4599106]: Building wheel for termcolor ( finished with status 'done'
2021-09-08T12:35:13.761909+00:00 shinyapps[4599106]: Building wheels for collected packages: termcolor, wrapt
2021-09-08T12:35:13.762447+00:00 shinyapps[4599106]: Building wheel for termcolor ( started
2021-09-08T12:35:13.978460+00:00 shinyapps[4599106]: Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=4847 sha256=ecf6bc899ff05a3e01b94365bd00682f5346051000ba9397bee95b001810f35e
2021-09-08T12:35:13.981102+00:00 shinyapps[4599106]: Building wheel for wrapt ( started
2021-09-08T12:35:13.978494+00:00 shinyapps[4599106]: Stored in directory: /home/shiny/.cache/pip/wheels/a0/16/9c/5473df82468f958445479c59e784896fa24f4a5fc024b0f501
2021-09-08T12:35:15.295751+00:00 shinyapps[4599106]: Building wheel for wrapt ( finished with status 'done'
2021-09-08T12:35:15.296506+00:00 shinyapps[4599106]: Created wheel for wrapt: filename=wrapt-1.12.1-cp38-cp38-linux_x86_64.whl size=78575 sha256=e75c03413c5fb5382cd09a92e2b518a1b8bb4d595ffdf9e8368d679dd54047f4
2021-09-08T12:35:15.298620+00:00 shinyapps[4599106]: Successfully built termcolor wrapt
2021-09-08T12:35:15.444900+00:00 shinyapps[4599106]: Installing collected packages: urllib3, pyasn1, idna, charset-normalizer, certifi, six, rsa, requests, pyasn1-modules, oauthlib, cachetools, requests-oauthlib, google-auth, werkzeug, tensorboard-plugin-wit, tensorboard-data-server, protobuf, numpy, markdown, grpcio, google-auth-oauthlib, absl-py, wrapt, typing-extensions, termcolor, tensorflow-estimator, tensorboard, opt-einsum, keras-preprocessing, h5py, google-pasta, gast, flatbuffers, astunparse, tensorflow-hub, tensorflow, pyyaml, Pillow, keras
2021-09-08T12:35:15.296565+00:00 shinyapps[4599106]: Stored in directory: /home/shiny/.cache/pip/wheels/5f/fd/9e/b6cf5890494cb8ef0b5eaff72e5d55a70fb56316007d6dfe73
2021-09-08T12:35:16.656624+00:00 shinyapps[4599106]: Attempting uninstall: numpy
2021-09-08T12:35:16.656877+00:00 shinyapps[4599106]: Found existing installation: numpy 1.21.2
2021-09-08T12:35:17.384876+00:00 shinyapps[4599106]: Uninstalling numpy-1.21.2:
2021-09-08T12:35:17.399381+00:00 shinyapps[4599106]: Successfully uninstalled numpy-1.21.2
2021-09-08T12:35:36.847074+00:00 shinyapps[4599106]: Successfully installed Pillow-8.3.2 absl-py-0.13.0 astunparse-1.6.3 cachetools-4.2.2 certifi-2021.5.30 charset-normalizer-2.0.4 flatbuffers-1.12 gast-0.3.3 google-auth-1.35.0 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.32.0 h5py-2.10.0 idna-3.2 keras-2.6.0 keras-preprocessing-1.1.2 markdown-3.3.4 numpy-1.19.5 oauthlib-3.1.1 opt-einsum-3.3.0 protobuf-3.17.3 pyasn1-0.4.8 pyasn1-modules-0.2.8 pyyaml-5.4.1 requests-2.26.0 requests-oauthlib-1.3.0 rsa-4.7.2 six-1.15.0 tensorboard-2.6.0 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.0 tensorflow-2.4.0 tensorflow-estimator-2.4.0 tensorflow-hub-0.12.0 termcolor-1.1.0 typing-extensions- urllib3-1.26.6 werkzeug-2.0.1 wrapt-1.12.1
2021-09-08T12:35:37.130182+00:00 shinyapps[4599106]:
2021-09-08T12:35:37.130184+00:00 shinyapps[4599106]: Installation complete.
2021-09-08T12:35:37.130185+00:00 shinyapps[4599106]:
2021-09-08T12:35:37.292705+00:00 shinyapps[4599106]: 2021-09-08 12:35:37.292441: W tensorflow/stream_executor/platform/default/] Could not load dynamic library ''; dlerror: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/shiny/.virtualenvs/myenv/lib:/opt/R/4.0.4/lib/R/lib:/usr/local/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/java-11-openjdk-amd64/lib/server
2021-09-08T12:35:37.292807+00:00 shinyapps[4599106]: 2021-09-08 12:35:37.292496: I tensorflow/stream_executor/cuda/] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-09-08T12:35:39.705337+00:00 shinyapps[4599106]: 2021-09-08 12:35:39.705235: I tensorflow/compiler/jit/] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-09-08T12:35:39.705814+00:00 shinyapps[4599106]: 2021-09-08 12:35:39.705776: W tensorflow/stream_executor/cuda/] failed call to cuInit: UNKNOWN ERROR (303)
2021-09-08T12:35:39.705801+00:00 shinyapps[4599106]: 2021-09-08 12:35:39.705736: W tensorflow/stream_executor/platform/default/] Could not load dynamic library ''; dlerror: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/shiny/.virtualenvs/myenv/lib:/opt/R/4.0.4/lib/R/lib:/usr/local/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/java-11-openjdk-amd64/lib/server
2021-09-08T12:35:39.705870+00:00 shinyapps[4599106]: 2021-09-08 12:35:39.705823: I tensorflow/stream_executor/cuda/] kernel driver does not appear to be running on this host (79b940c5198d): /proc/driver/nvidia/version does not exist
2021-09-08T12:35:39.706108+00:00 shinyapps[4599106]: 2021-09-08 12:35:39.706053: I tensorflow/core/platform/] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX512F
2021-09-08T12:35:39.706109+00:00 shinyapps[4599106]: To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-09-08T12:35:39.707015+00:00 shinyapps[4599106]: 2021-09-08 12:35:39.706958: I tensorflow/compiler/jit/] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-09-08T12:35:58.086329+00:00 shinyapps[4599106]:
2021-09-08T12:35:58.086333+00:00 shinyapps[4599106]: Listening on
2021-09-08T12:36:10.561450+00:00 shinyapps[4599106]: 2021-09-08 12:36:10.561385: I tensorflow/core/platform/profile_utils/] CPU Frequency: 3000000000 Hz
2021-09-08T12:36:10.561023+00:00 shinyapps[4599106]: 2021-09-08 12:36:10.560913: I tensorflow/compiler/mlir/] None of the MLIR optimization passes are enabled (registered 2)
2021-09-08T12:36:12.719962+00:00 shinyapps[4599106]: Warning: Error in order: Argument 1 is not a vector
2021-09-08T12:36:12.726522+00:00 shinyapps[4599106]: 128: order
2021-09-08T12:36:12.726525+00:00 shinyapps[4599106]: 125: reactive:prediction [/srv/connect/apps/birdapp/app.R#156]
2021-09-08T12:36:12.726526+00:00 shinyapps[4599106]: 109: prediction
2021-09-08T12:36:12.726528+00:00 shinyapps[4599106]: 94: renderFunc
2021-09-08T12:36:12.726528+00:00 shinyapps[4599106]: 93: output$text
2021-09-08T12:36:12.726530+00:00 shinyapps[4599106]: 6: eval
2021-09-08T12:36:12.726529+00:00 shinyapps[4599106]: 12: fn
2021-09-08T12:36:12.726529+00:00 shinyapps[4599106]: 7: connect$retry
2021-09-08T12:36:12.726526+00:00 shinyapps[4599106]: 108: renderTable [/srv/connect/apps/birdapp/app.R#162]
2021-09-08T12:36:12.732958+00:00 shinyapps[4599106]: 112:
2021-09-08T12:36:12.726527+00:00 shinyapps[4599106]: 107: func
2021-09-08T12:36:12.726528+00:00 shinyapps[4599106]: 13: runApp
2021-09-08T12:36:12.729641+00:00 shinyapps[4599106]: Warning: Error in order: Argument 1 is not a vector
2021-09-08T12:36:12.726540+00:00 shinyapps[4599106]: 5: eval

My best guess is that you have path error issues on the server. It looks like you can't load dependencies because the folder path 'LD_LIBRARY_PATH' is incorrect.

Could not load dynamic library ''; dlerror: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH:


Could not load dynamic library ''; dlerror: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH:

You could try reinstalling:

Might help; might not.

Thank you for your response? I have the GPU version of Tensorflow set up on my computer, but the version here is just looking to the CPU one. Does anyone know how to specify your CUDA installation on the Shiny server?

Any advice would be greatly appreciated!

You are trying to deploy to, so the app has to be executable with the resources available at their servers and as far as I know they do not have the option to use GPU accelerated workers so it is not currently possible to use the GPU version.

thank you for your comment!! Do you think this would be a problem if my model was trained using the GPU version? As you can see from the logs, it still accessed the CPU version of TensorFlow - but I'm still not certain what the Argument 1 is not a vector refers to?

This topic was automatically closed 54 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.