Please help with deploying App that runs perfectly locally

I am trying to publish my small little shiny application via shinapps.io. But I get the following error message:

Error in func(fname, ...) : app.R did not return a shiny.appobj object.
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted

Can someone help by looking at my code? Thanks in advance!

Best regards

library(shiny)
library(ggplot2)
library(patchwork)
library(scales)

# UI für die Shiny App
ui <- fluidPage(
  titlePanel("Lineare Regression"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("inter", "Achsenabschnitt:", value = 10000, min = 8500, max = 11000),
      sliderInput("sl", "Steigung:", value = -10, min = -300, max = 200)
    ),
    
    mainPanel(
               h4("Funktionweise und Ziel"),
               h6("Mit dieser App können Sie prüfen, welche Geradengleichung eine optimale Anpassung (im Sinne des KQ-Kriteriums) an gegebene Daten ermöglicht. 
                  Dazu finden Sie hier Daten zu Preisen und bei diesen Preisen realisierte Mengen. Ihr Ziel ist die Entwicklung einer möglichst guten
                  Preis-Absatz-Funktion. Wählen Sie dazu eine Steigung und einen Achsenabschnitt für ihre Funktion auf der linken Seite aus. Sie sehen dann
                  in der linken Visualisierung, wie nah ihre Gerade an den Ausgangsdaten ist (die vertikalen Linien zeigen Ihnen die Abweichung zwischen beobachteten Werten und der Prognose). 
                  Auf der rechten Seite sehen Sie das Ergebnis einer linearen
                  Regression. Im unteren Panel können Sie die (Sum of Squares Residuals) für beide Konfigurationen vergleichen"),
      
               plotOutput("comb_plot", width="100%"),
               plotOutput("sse_plot", width="100%", height="200px")

      )
  )
)
# Server-Funktion für die Shiny App
server <- function(input, output) {
  
 
    output$comb_plot <- renderPlot({
        
        inter <- input$inter
        sl <- input$sl
        
        Preis <- seq(1,10.5,0.5)
        data <- data.frame(Preis, "Menge"= c(9763,9439,9101,8850,8908,9031,9076,9096,
                                             9123, 9305, 8680, 8438, 9090, 8629, 8825, 8381,
                                             8572, 8397, 8281, 8726))
        
        pred <- sl *data$Preis + inter
        model <- lm(Menge ~ Preis, data=data)
        pred_lm <- -100.83*data$Preis + 9465.33
        resi_sse <- data.frame("Prognose"= c("Manuell", "lin. Regression") ,"SSE" = c(sum((data$Menge - pred)^2), sum((data$Menge - pred_lm)^2)))
        
        
        p1 <- ggplot(data, aes(Preis,Menge)) + geom_point() + geom_abline(slope = sl, intercept = inter) + geom_point(aes(y=pred), shape = 1)+
          geom_segment(aes(xend=Preis, yend = pred), colour="blue", linewidth = 1.0) + ggtitle("Manuelle Wahl der Parameter")
        
        
        p2 <- ggplot(data, aes(Preis,Menge)) + geom_point() + geom_abline(slope = model$coefficients[2], intercept = model$coefficients[1]) + geom_point(aes(y=pred_lm), shape = 1)+
          geom_segment(aes(xend=Preis, yend = pred_lm), colour="red", linewidth = 1.0) +ggtitle("Regression mittles KQ-Schätzung")
        
        p1+p2 + plot_layout(ncol=2)
        
        
    })
      
    output$sse_plot <- renderPlot({
       
      
      inter <- input$inter
      sl <- input$sl
      
      Preis <- seq(1,10.5,0.5)
      data <- data.frame(Preis, "Menge"= c(9763,9439,9101,8850,8908,9031,9076,9096,
                                           9123, 9305, 8680, 8438, 9090, 8629, 8825, 8381,
                                           8572, 8397, 8281, 8726))
      
      pred <- sl *data$Preis + inter
      model <- lm(Menge ~ Preis, data=data)
      pred_lm <- -100.83*data$Preis + 9465.33
      resi_sse <- data.frame("Art"= c("Manuell", "lin. Regression") ,"SSE" = c(sum((data$Menge - pred)^2), sum((data$Menge - pred_lm)^2)))
      
      ggplot(resi_sse, aes(y = Art, x = SSE, fill = Art)) + geom_bar(stat = "identity", fill=c("blue","red")) +
        scale_x_continuous(labels= comma_format(big.mark = ".", decimal.mark=",")) + ggtitle("Prognosegüte (Sum of Squared Residuals) im Vergleich")+
        theme(legend.position="bottom") 
      
    })
      
}

# Shiny App starten
shinyApp(ui = ui, server = server)



I want to add the following to the problem:

I tried using the exact code as given in chapter 3 of "Mastering Shiny" (Chapter 3 Basic reactivity | Mastering Shiny) to create a Shiny App that I want to publish on Shinyapps.io.

I get the following (same) error:

2023-08-23T07:41:53.383445+00:00 shinyapps[9659932]: Connect version: 2023.03.0
2023-08-23T07:41:53.387088+00:00 shinyapps[9659932]: LANG: C.UTF-8
2023-08-23T07:41:53.390593+00:00 shinyapps[9659932]: Working directory: /srv/connect/apps/linreg
2023-08-23T07:41:53.394267+00:00 shinyapps[9659932]: Using R 4.3.1
2023-08-23T07:41:53.397962+00:00 shinyapps[9659932]: R.home(): /opt/R/4.3.1/lib/R
2023-08-23T07:41:53.401730+00:00 shinyapps[9659932]: Content will use current R environment
2023-08-23T07:41:53.405426+00:00 shinyapps[9659932]: R_LIBS: (unset)
2023-08-23T07:41:53.408955+00:00 shinyapps[9659932]: .libPaths(): /opt/R/4.3.1/lib/R/library
2023-08-23T07:41:53.412749+00:00 shinyapps[9659932]: shiny version: 1.7.5
2023-08-23T07:41:53.417361+00:00 shinyapps[9659932]: httpuv version: 1.6.11
2023-08-23T07:41:53.420968+00:00 shinyapps[9659932]: rmarkdown version: (none)
2023-08-23T07:41:53.424799+00:00 shinyapps[9659932]: knitr version: (none)
2023-08-23T07:41:53.428678+00:00 shinyapps[9659932]: jsonlite version: 1.8.7
2023-08-23T07:41:53.432346+00:00 shinyapps[9659932]: RJSONIO version: (none)
2023-08-23T07:41:53.436044+00:00 shinyapps[9659932]: htmltools version: 0.5.5
2023-08-23T07:41:53.439713+00:00 shinyapps[9659932]: reticulate version: (none)
2023-08-23T07:41:53.443404+00:00 shinyapps[9659932]: Using pandoc: /opt/connect/ext/pandoc/2.16
2023-08-23T07:41:53.447258+00:00 shinyapps[9659932]:
2023-08-23T07:41:53.451053+00:00 shinyapps[9659932]: Starting R with process ID: '53'
2023-08-23T07:41:53.454666+00:00 shinyapps[9659932]: Shiny application starting ...
2023-08-23T07:41:53.458122+00:00 shinyapps[9659932]: Shiny application exiting ...
2023-08-23T07:41:53.462035+00:00 shinyapps[9659932]: Error in func(fname, ...) : app.R did not return a shiny.appobj object.
2023-08-23T07:41:53.465669+00:00 shinyapps[9659932]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
2023-08-23T07:41:53.469290+00:00 shinyapps[9659932]: Execution halted

This is the code used:

library(shiny)
library(ggplot2)


freqpoly <- function(x1, x2, binwidth = 0.1, xlim = c(-3, 3)) {
  df <- data.frame(
    x = c(x1, x2),
    g = c(rep("x1", length(x1)), rep("x2", length(x2)))
  )
  
  ggplot(df, aes(x, colour = g)) +
    geom_freqpoly(binwidth = binwidth, size = 1) +
    coord_cartesian(xlim = xlim)
}

t_test <- function(x1, x2) {
  test <- t.test(x1, x2)
  
# use sprintf() to format t.test() results compactly
  sprintf(
    "p value: %0.3f\n[%0.2f, %0.2f]",
    test$p.value, test$conf.int[1], test$conf.int[2]
  )
}

ui <- fluidPage(
  fluidRow(
    column(4, 
           "Distribution 1",
           numericInput("n1", label = "n", value = 1000, min = 1),
           numericInput("mean1", label = "µ", value = 0, step = 0.1),
           numericInput("sd1", label = "σ", value = 0.5, min = 0.1, step = 0.1)
    ),
    column(4, 
           "Distribution 2",
           numericInput("n2", label = "n", value = 1000, min = 1),
           numericInput("mean2", label = "µ", value = 0, step = 0.1),
           numericInput("sd2", label = "σ", value = 0.5, min = 0.1, step = 0.1)
    ),
    column(4,
           "Frequency polygon",
           numericInput("binwidth", label = "Bin width", value = 0.1, step = 0.1),
           sliderInput("range", label = "range", value = c(-3, 3), min = -5, max = 5)
    )
  ),
  fluidRow(
    column(9, plotOutput("hist")),
    column(3, verbatimTextOutput("ttest"))
  )
)

server <- function(input, output, session) {
  output$hist <- renderPlot({
    x1 <- rnorm(input$n1, input$mean1, input$sd1)
    x2 <- rnorm(input$n2, input$mean2, input$sd2)
    
    freqpoly(x1, x2, binwidth = input$binwidth, xlim = input$range)
  }, res = 96)
  
  output$ttest <- renderText({
    x1 <- rnorm(input$n1, input$mean1, input$sd1)
    x2 <- rnorm(input$n2, input$mean2, input$sd2)
    
    t_test(x1, x2)
  })
}

shinyApp(ui = ui, server = server)

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.