I am trying to publish an app on shinyapps.io that works perfectly fine locally, but when I upload it online, I get the following error:
Error in func(fname, …) : app.R did not return a shiny.appobj object.
and this o the browser page:
An error has occurred
The application failed to start.
exit status 1
Here the code for the app:
library(shiny)
library("shinythemes")
library("randomForest")
library("data.table")
library("RCurl")
rf_model <- readRDS("rf_model1.rds")
###############################
ui <- fluidPage(
theme = shinytheme("united"),
titlePanel( "Maximal Ischemia Time Calculator"),
sidebarPanel(
sliderInput(inputId = "age",
label = "Age:",
min = 18,
max = 100,
value = 60,
step = 1),
selectInput(inputId = "cci",
label = "CCI:",
choices = list("0" = "0", "1" = "1", "2" = "2", "3+" = ">2"),
selected = "0"),
selectInput(inputId = "asa",
label = "ASA score:",
choices = list("1" = "1", "2" = "2", "3" = "3", "4" = "4"),
selected = "1"),
selectInput(inputId = "hypertension",
label = "Hypertension:",
choices = list("Yes" = "1", "No" = "0"),
selected = "No"),
sliderInput(inputId = "hb.pre",
label = "Preoperative Hb:",
min = 3.0,
max = 20.0,
value = 13.0,
step = 0.1),
sliderInput(inputId = "gfr.pre",
label = "Preoperative eGFR:",
min = 10.0,
max = 150.0,
value = 60.0,
step = 0.1),
sliderInput(inputId = "c.size",
label = "Tumour dimensions (cm):",
min = 0.1,
max = 20.0,
value = 2.0,
step = 0.1),
selectInput(inputId = "renal.class",
label = "RENAL Score:",
choices = list("Low Risk" = "1", "Intermediate Risk" = "2", "High Risk" = "3"),
selected = "Low Risk"),
actionButton("submitbutton", "Submit", class = "btn btn-primary")),
mainPanel
(
tags$label(h3('Results')), # Status/Output Text Box
verbatimTextOutput('contents'),
verbatimTextOutput('results')
))
server <- function(input, output, session) {
datasetInput <- reactive({
df <- data.frame(
Name = c("age",
"cci",
"asa",
"hypertension",
"hb.pre",
"gfr.pre",
"c.size",
"renal.class"),
Value = as.character(c(input$age,
input$cci,
input$asa,
input$hypertension,
input$hb.pre,
input$gfr.pre,
input$c.size,
input$renal.class)),
stringsAsFactors = FALSE)
ischemia.time <- "ischemia.time"
df <- rbind(df, ischemia.time)
input <- transpose(df)
write.table(input,"input.csv", sep=",", quote = FALSE, row.names = FALSE, col.names = FALSE)
test <- read.csv(paste("input", ".csv", sep=""), header = TRUE)
test$age <- as.numeric(test$age)
test$hb.pre <- as.numeric(test$hb.pre)
test$gfr.pre <- as.numeric(test$gfr.pre)
test$c.size <- as.numeric(test$c.size)
test$cci <- factor(test$cci, levels = c("0", "1", "2", ">2"))
test$asa <- factor(test$asa, levels = c("1", "2", "3", "4"))
test$hypertension <- factor(test$hypertension, levels = c("1", "0"))
test$renal.class <- factor(test$renal.class, levels = c("1", "2", "3"))
find_max_ischemia_time <- function(data, rf_model, p.critico)
{
t_min <- 1
t_max <- 60
t_final <- t_min
while (t_final < t_max)
{
data$ischemia.time <- as.numeric(t_final)
p_danno <- (predict(rf_model, data , type = "prob")[,2])
if (p_danno <= p.critico)
{
t_final <- t_final + 1 # Aumenta il tempo minimo
}
else
{
t_result <- t_final
return(t_result)
}
}
return(t_result)
}
Output <- find_max_ischemia_time(test, rf_model, p.critico = 0.10)
print(paste("The recommended maximum ischemia time is:", Output, "minutes"))
})
# Status/Output Text Box
output$contents <- renderPrint({
if (input$submitbutton>0) {
isolate("Calculation complete.")
} else {
return("Server is ready for calculation.")
}
})
# Prediction results table
output$results <- renderPrint({
if (input$submitbutton>0) {
isolate(datasetInput())
}})
}
shinyApp(ui = ui, server = server)
I tried debugging my code but i don’t see anything that seems wrong to me
5