App.R did not return a shiny.appobj object error after deploying

I am trying to deploy my shiny app to shinyapps.io. However, when I deploy I get the error message:

An error has occurred
The application failed to start (exited with code 1).
Error in value[[3L]](cond) : app.R did not return a shiny.appobj object.
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

Note- the app runs in my local. Here is the entire log:


2019-12-15T07:21:52.731062+00:00 shinyapps[1600874]: Server version: 1.7.8-7
2019-12-15T07:21:52.731064+00:00 shinyapps[1600874]: LANG: en_US.UTF-8
2019-12-15T07:21:52.874145+00:00 shinyapps[1600874]: 
2019-12-15T07:21:52.731093+00:00 shinyapps[1600874]: R version: 3.6.1
2019-12-15T07:21:52.874191+00:00 shinyapps[1600874]: Starting R with process ID: '25'
2019-12-15T07:21:52.731094+00:00 shinyapps[1600874]: shiny version: 1.4.0
2019-12-15T07:21:52.897048+00:00 shinyapps[1600874]: Error in value[[3L]](cond) : app.R did not return a shiny.appobj object.
2019-12-15T07:21:52.731095+00:00 shinyapps[1600874]: httpuv version: 1.5.2
2019-12-15T07:21:52.897050+00:00 shinyapps[1600874]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
2019-12-15T07:21:52.731109+00:00 shinyapps[1600874]: knitr version: (none)
2019-12-15T07:21:52.897051+00:00 shinyapps[1600874]: Execution halted
2019-12-15T07:21:52.731110+00:00 shinyapps[1600874]: jsonlite version: 1.6
2019-12-15T07:21:52.731117+00:00 shinyapps[1600874]: RJSONIO version: (none)
2019-12-15T07:21:52.731201+00:00 shinyapps[1600874]: htmltools version: 0.4.0
2019-12-15T07:21:52.731268+00:00 shinyapps[1600874]: Using pandoc at /opt/connect/ext/pandoc2
2019-12-15T07:21:52.866318+00:00 shinyapps[1600874]: Using jsonlite for JSON processing
2019-12-15T07:21:52.731095+00:00 shinyapps[1600874]: rmarkdown version: (none)
2019-12-15T07:22:02.078718+00:00 shinyapps[1600874]: Server version: 1.7.8-7
2019-12-15T07:22:02.078759+00:00 shinyapps[1600874]: LANG: en_US.UTF-8
2019-12-15T07:22:02.078760+00:00 shinyapps[1600874]: R version: 3.6.1
2019-12-15T07:22:02.078761+00:00 shinyapps[1600874]: shiny version: 1.4.0
2019-12-15T07:22:02.078773+00:00 shinyapps[1600874]: httpuv version: 1.5.2
2019-12-15T07:22:02.078774+00:00 shinyapps[1600874]: rmarkdown version: (none)
2019-12-15T07:22:02.078787+00:00 shinyapps[1600874]: knitr version: (none)
2019-12-15T07:22:02.078796+00:00 shinyapps[1600874]: jsonlite version: 1.6
2019-12-15T07:22:02.078835+00:00 shinyapps[1600874]: RJSONIO version: (none)
2019-12-15T07:22:02.078836+00:00 shinyapps[1600874]: htmltools version: 0.4.0
2019-12-15T07:22:02.078986+00:00 shinyapps[1600874]: Using pandoc at /opt/connect/ext/pandoc2
2019-12-15T07:22:02.216955+00:00 shinyapps[1600874]: Using jsonlite for JSON processing
2019-12-15T07:22:02.249705+00:00 shinyapps[1600874]: Error in value[[3L]](cond) : app.R did not return a shiny.appobj object.
2019-12-15T07:22:02.225593+00:00 shinyapps[1600874]: 
2019-12-15T07:22:02.225595+00:00 shinyapps[1600874]: Starting R with process ID: '42'
2019-12-15T07:22:02.249706+00:00 shinyapps[1600874]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
2019-12-15T07:22:02.249727+00:00 shinyapps[1600874]: Execution halted
2019-12-15T07:26:23.169853+00:00 shinyapps[1600874]: Server version: 1.7.8-7
2019-12-15T07:26:23.169854+00:00 shinyapps[1600874]: LANG: en_US.UTF-8
2019-12-15T07:26:23.169892+00:00 shinyapps[1600874]: R version: 3.6.1
2019-12-15T07:26:23.169894+00:00 shinyapps[1600874]: shiny version: 1.4.0
2019-12-15T07:26:23.169894+00:00 shinyapps[1600874]: httpuv version: 1.5.2
2019-12-15T07:26:23.169895+00:00 shinyapps[1600874]: rmarkdown version: (none)
2019-12-15T07:26:23.169895+00:00 shinyapps[1600874]: knitr version: (none)
2019-12-15T07:26:23.169896+00:00 shinyapps[1600874]: jsonlite version: 1.6
2019-12-15T07:26:23.169905+00:00 shinyapps[1600874]: RJSONIO version: (none)
2019-12-15T07:26:23.169905+00:00 shinyapps[1600874]: htmltools version: 0.4.0
2019-12-15T07:26:23.170057+00:00 shinyapps[1600874]: Using pandoc at /opt/connect/ext/pandoc2
2019-12-15T07:26:23.303462+00:00 shinyapps[1600874]: Using jsonlite for JSON processing
2019-12-15T07:26:23.311486+00:00 shinyapps[1600874]: 
2019-12-15T07:26:23.311487+00:00 shinyapps[1600874]: Starting R with process ID: '123'
2019-12-15T07:26:23.334609+00:00 shinyapps[1600874]: Error in value[[3L]](cond) : app.R did not return a shiny.appobj object.
2019-12-15T07:26:23.334609+00:00 shinyapps[1600874]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
2019-12-15T07:26:23.334622+00:00 shinyapps[1600874]: Execution halted

This is the code for the app

library(shiny)
library(shinyWidgets)
library(tidyverse)
library(reticulate)
library(DT)
library(knitr)
library(data.table)
use_python('C:\\Users\\User\\Anaconda3\\python.exe')
# boxing = read.csv(file="https://raw.githubusercontent.com/EmmS21/SpringboardCapstoneBoxingPredictionWebApp/master/boxingdata/visuals.csv",header=TRUE)
boxing <- readRDS('boxingdatafull2.rds')
#reading model
p <- import("pandas")
cat_model <- p$read_pickle("catmodelsummary.pkl")
ui <- shinyUI(
  fluidPage(setBackgroundImage(src = "mayweather2.png"),
            headerPanel(fluidRow(
              column(offset = 5, width=5,
                     h2("Boxing Prediction App")),
              column(offset = 3, width = 7,
                     h5("Welcome to Emmanuel's boxing prediction app. Using this app you can get the probability of a fight ending in a given way. The model used to derive these predictions uses data extracted before the 23rd of November 2019. Any updates to the data will be shown here. Without further ado, let's get ready to rumble!"))
            )),
            fluidRow(column(offset = 5, width = 2,align="center",
                            titlePanel(h5(selectInput("dropdown","Select Boxer Weights",choices=unique(boxing$division)))))),
            fluidRow(column(offset = 3, width=3,
                            wellPanel(
                              fluidRow(
                                uiOutput("Names"),
                                uiOutput("boxerA")))),
                     column(width = 3, align="right",
                            wellPanel(style = "height:300px",
                                      fluidRow(
                                        uiOutput("Opponent"),
                                        uiOutput("opppic")
                                      )))),
            hr(),
            column(offset=5,width = 8,
                   actionButton("goButton","Start Predictions")),
            hr(),
            column(offset=3,width=6,
                   DTOutput("predictions"))
            # ,
            # hr(),
            # column(offset=5,width = 5, 
            #        uiOutput("boxergifs"))
  ) 
)

server <- function(input,output){
  output$Names <- renderUI({
    req(input$dropdown)
    df <- boxing %>% filter(division %in% input$dropdown)
    selectInput("names","Boxer A",choices = df$name)
  })
  output$boxerA <- renderUI({
    print(paste(boxing[boxing$name == input$names, "global_id"],".jpg",sep=""))
    tags$img(src=paste(boxing[boxing$name == input$names, "global_id"],".jpg",sep=""),width=150)
  })
  output$Opponent <- renderUI({
    req(input$dropdown)
    df <- boxing %>% filter(division %in% input$dropdown)
    selectInput("names2","Opponent",choices = df$name)
  })
  output$opppic <- renderUI({
    tags$img(src=paste(boxing[boxing$name == input$names2, "global_id"],".jpg",sep=""),width=150)
  })
  
  
  observeEvent(input$goButton, {
    
    output$predictions <- renderDataTable({
      df1 <- boxing %>% filter(name %in% input$names)
      df2 <- boxing %>% filter(name %in% input$names2)
      df2$opp_loss <- df2$Loss.KO + df2$Loss.Other
      df2$opp_win <- df2$Win.KO + df2$Win.Other
      df1 <- df1 %>% select(Win.KO,Loss.Other,Loss.KO,Win.Other,KO.ratio,KnockedOut.ratio,Draw)
      df2 <- df2 %>% select(last6,KO.ratio,Win.Other,Win.KO,opp_loss,Loss.Other,opp_win,Loss.KO)
      setnames(df1,c("Win.KO","Loss.Other","Loss.KO","Win.Other","KO.ratio","KnockedOut.ratio"),c("winKO","lossOther","lossKO","winOther","KOratio","Knockedoutratio"))
      setnames(df2,c("last6","KO.ratio","Win.Other","Win.KO","Loss.Other","Loss.KO"), c("opp_last6","oppKOratio","opp_winOther","opp_winKO","opp_lossOther","opp_lossKO"))
      preds <- df1[,c("winKO","lossOther","lossKO","winOther","KOratio","Knockedoutratio","Draw")]
      preds2 <- df2[,c("opp_last6","oppKOratio","opp_winOther","opp_winKO","opp_loss","opp_lossOther","opp_win","opp_lossKO")]
      preds3 <- bind_cols(preds,preds2)
      df <- data.frame(probs = round(cat_model$predict_proba(preds3)*100,2))
      names(df)[1] <- "Draw"
      names(df)[2] <- "Loss"
      names(df)[3] <- "Win"
      #custom table
      datatable(df, container = htmltools::withTags(table(tableHeader(df))),options = list(pageLength=1,dom='tip'), rownames = FALSE, class = 'cell-border stripe')
    })
    
  })
}
shinyApp(ui = ui, server = server)
1 Like

This line is not going to work on shinyapps.io because you are using a local path that doesn't exist on the server and for using python libraries on shinyapps.io, you have to explicitly install them, try with something like this.

library(reticulate)
# Create a virtual environment selecting your desired python version
virtualenv_create(envname = "python_environment", python= "python3")
# Explicitly install python libraries that you want to use, e.g. pandas, numpy
virtualenv_install("python_environment", packages = c('pandas','numpy')
# Select the virtual environment
use_virtualenv("python_environment", required = TRUE)
`

Thanks. Getting the error message:

Warning: running command '"python3" -E -c "import platform; print(platform.python_version())"' had status 9009
Error in if (py_version >= "3.6") modules <- c("venv", modules) : 
  argument is of length zero

When I try and run the app in local with these changes

You can't use the same path locally and in shinyapps.io, have in mind that shinyapps.io runs on a Linux server and your local OS is Windows.

I see. Still getting the error

ERROR: The requested version of Python
('~/.virtualenvs/python_environment/bin/python') cannot be used, as
another version of Python ('/usr/bin/python') has already been
initialized. Please restart the R session if you need to attach
reticulate to a different version of Python.
Error in value[[3L]](cond) : 
  failed to initialize requested version of Python

Have tried restarting my R session and redeploying multiple times

Can you show your new code? Are you deleting the cached data before redeploying?

Here.

library(shiny)
library(shinyWidgets)
library(tidyverse)
library(reticulate)
library(DT)
library(data.table)
virtualenv_create(envname = "python_environment",python="python3")
virtualenv_install("python_environment", packages =c('pandas','numpy'))
use_virtualenv("python_environment",required = TRUE)
# boxing = read.csv(file="https://raw.githubusercontent.com/EmmS21/SpringboardCapstoneBoxingPredictionWebApp/master/boxingdata/visuals.csv",header=TRUE)
boxing <- readRDS('fullboxingdataset.RDS')
#reading model
p <- import("pandas")
cat_model <- p$read_pickle("catmodelsummary.pkl")
ui <- function(){
  addResourcePath("www","www")
  tagList(
    shinyUI(
      fluidPage(setBackgroundImage(src = "www/mayweather2.png"),
                headerPanel(fluidRow(
                  column(offset = 5, width=5,
                         h2("Boxing Prediction App")),
                  column(offset = 3, width = 7,
                         h5("Welcome to Emmanuel's boxing prediction app. Using this app you can get the probability of a fight ending in a given way. The model used to derive these predictions uses data extracted before the 23rd of November 2019. Any updates to the data will be shown here. Without further ado, let's get ready to rumble!"))
                )),
                fluidRow(column(offset = 5, width = 2,align="center",
                                titlePanel(h5(selectInput("dropdown","Select Boxer Weights",choices=unique(boxing$division)))))),
                fluidRow(column(offset = 3, width=3,
                                wellPanel(
                                  fluidRow(
                                    uiOutput("Names"),
                                    uiOutput("boxerA")))),
                         column(width = 3, align="right",
                                wellPanel(style = "height:300px",
                                          fluidRow(
                                            uiOutput("Opponent"),
                                            uiOutput("opppic")
                                          )))),
                hr(),
                column(offset=5,width = 8,
                       actionButton("goButton","Start Predictions")),
                hr(),
                column(offset=3,width=6,
                       DTOutput("predictions"))
      ) 
    )
  )}

server <- function(input,output){
  output$Names <- renderUI({
    req(input$dropdown)
    df <- boxing %>% filter(division %in% input$dropdown)
    selectInput("names","Boxer A",choices = df$name)
  })
  output$boxerA <- renderUI({
    tags$img(src=paste("www/",boxing[boxing$name == input$names, "global_id"],".jpg",sep=""),width=150)
  })
  output$Opponent <- renderUI({
    req(input$dropdown)
    df <- boxing %>% filter(division %in% input$dropdown)
    selectInput("names2","Opponent",choices = df$name)
  })
  output$opppic <- renderUI({
    tags$img(src=paste("www/",boxing[boxing$name == input$names2, "global_id"],".jpg",sep=""),width=150)
  })
  
  
  observeEvent(input$goButton, {
    
    output$predictions <- renderDataTable({
      df1 <- boxing %>% filter(name %in% input$names)
      df2 <- boxing %>% filter(name %in% input$names2)
      df2$opp_loss <- df2$Loss.KO + df2$Loss.Other
      df2$opp_win <- df2$Win.KO + df2$Win.Other
      df1 <- df1 %>% select(Win.KO,Loss.Other,Loss.KO,Win.Other,KO.ratio,KnockedOut.ratio,Draw)
      df2 <- df2 %>% select(last6,KO.ratio,Win.Other,Win.KO,opp_loss,Loss.Other,opp_win,Loss.KO)
      setnames(df1,c("Win.KO","Loss.Other","Loss.KO","Win.Other","KO.ratio","KnockedOut.ratio"),c("winKO","lossOther","lossKO","winOther","KOratio","Knockedoutratio"))
      setnames(df2,c("last6","KO.ratio","Win.Other","Win.KO","Loss.Other","Loss.KO"), c("opp_last6","oppKOratio","opp_winOther","opp_winKO","opp_lossOther","opp_lossKO"))
      preds <- df1[,c("winKO","lossOther","lossKO","winOther","KOratio","Knockedoutratio","Draw")]
      preds2 <- df2[,c("opp_last6","oppKOratio","opp_winOther","opp_winKO","opp_loss","opp_lossOther","opp_win","opp_lossKO")]
      preds3 <- bind_cols(preds,preds2)
      df <- data.frame(probs = round(cat_model$predict_proba(preds3)*100,2))
      names(df)[1] <- "Draw"
      names(df)[2] <- "Loss"
      names(df)[3] <- "Win"
      #custom table
      datatable(df, container = htmltools::withTags(table(tableHeader(df))),options = list(pageLength=1,dom='tip'), rownames = FALSE, class = 'cell-border stripe')
    })
  })
}
shinyApp(ui = ui, server = server)

Did you manage to solve it? I am currently going through the same problem.