Problem with crashing app in Shinyapps.io

Hello,

I am having problem with one application that is loaded in shinyapps.io. When I run it locally everything is ok, but when I put it in shinyapps.io crashes.

library("aws.s3")
library("ncdf4")
library("sp")
library("sf")
library("dplyr")
library("shiny")
library("shinyWidgets")
library("shinydashboard")
library("waiter")
library("leaflet")
library("rlist")
library("graphics")
library("fields")
library("raster")
library("RColorBrewer")
library("purrr")
library("ggplot2")
library("png")
library("patchwork")
library("DT") # librería para las fcs: dataTableOutput() y renderDataTable()
library("tidyr")
library("xts")
library("dygraphs")
library("viridis")
library("terra")
library("lubridate")

#Sys.setenv(TZ = "America/Argentina/Buenos_Aires")

------------------------------------------------------------------------------

Funciones utilizadas en la app

source("./00_fct.R")
source("./00_fct-ITH.R")

------------------------------------------------------------------------------

Configuracion de UI

ui <- dashboardPage(skin = "green",

dashboardHeader(title = "Productos de las salidas SMN Hi-Res Weather Forecast AWS",
titleWidth = 600),

dashboardSidebar(
tags$style(HTML("

  /* Cambiar el color de fondo del sidebar */
  .main-sidebar {
    background-color: #CDCDCD !important; /* Color tonalidad gris */
    }")),

sidebarMenu(
  
  waiter::use_waiter(),
  
  
  tags$div(
    style = "display: inline-block; background-color: #BBBBBB; padding: 5px;",
    tags$img(src = "logoSMN-75x80.png", width = "75px")),
  
  tags$span(style = "color: #000046; font-size: 18px; font-weight: bold;",
            "Servicio Meteorológico Nacional"),
  
  dateInput("fecha.tab1", label = div(style = "color: black;",
                                      "Seleccione una fecha de pronóstico"),
            value = as.Date("2025-01-15"),
            min = as.Date("2025-01-01"),
            max = as.Date("2025-01-15")),
  
  selectInput("ciclo.tab1",
              label = div(style = "color: black;", "Selección del ciclo de pronóstico"),
              choices = c("00", "06", "12", "18"),
              selected = "00"),
                   
  selectInput("time.tab1",
              label = div(style = "color: black;", "Selección del dataset (plazo de pronóstico)"),
              choices = c("24H", "01H"),
              selected = "24H"),
  
  actionButton("descarga", "DESCARGA DE DATOS",
               style = "background-color: #3F704D",
               class = "btn-lg btn-success",
               icon = icon("download")),
  
  tags$br(), tags$br(), tags$br(), tags$br(),
  
  tags$div(
    style = "display: flex; justify-content: center; align-items: center; height: 100%",
    actionButton("Calcular_ith", "Calcular ITH-WRF-DET",
                 style = "background-color: #3F704D",
                 class = "btn-lg btn-success")),
  
  tags$br(),
  
  uiOutput("tabSelection")

  ), width = 350

),

dashboardBody(fluidPage(
tabsetPanel(id="tabs1",

  tabPanel("Productos ITH WRF-DET", value = 2,
           fluidRow(
             column(width=3, tags$a(
             href = "https://repositorio.smn.gob.ar/bitstream/handle/20.500.12160/2875/Nota_Tecnica_SMN_2024-182.pdf?sequence=1&isAllowed=y",
             target = "_blank",
             infoBox("Documentación", "Haga click aquí", icon = icon("book"), width = "100%"))),
             
             column(width=3, infoBox("", "Consultas", "gdiaz@smn.gob.ar", width="100%", icon=icon("question")))),
           
           box(title = "Mapas de ITH WRF-DET",
               collapsible = TRUE, width = 6,
               imageOutput("image_ith"), height = "1000px"),
           box(title = "Series Temporales de ITH WRF-DET",
               collapsible = TRUE, width = 6, height = 500,
               textOutput("plot_ith")),
           box(title = "Series Temporales de ITH WRF-DET: Nuevo producto (horas mayor a umbral)",
               collapsible = TRUE, width = 6, height = 500,
               imageOutput("plot_new_ith")),
           box(title = "Mapas interactivo",
               collapsible = TRUE, width = 6,
               leafletOutput("leaflet_ith", height = "1000px"))
           ),
  tabPanel("Productos ITH WRF-ENS (desactualizado)", value = 2,
           fluidRow(
             column(width=3, tags$a(
             href = "https://repositorio.smn.gob.ar/bitstream/handle/20.500.12160/2875/Nota_Tecnica_SMN_2024-182.pdf?sequence=1&isAllowed=y",
             target = "_blank",
             infoBox("Documentación", "Haga click aquí", icon = icon("book"), width = "100%"))),
          
             column(width=3, infoBox("", "Consultas", "gdiaz@smn.gob.ar", width = "100%", icon = icon("question")))),
           
           box(title = "Mapas de probabilidad de ITH WRF-ENS",
               collapsible = TRUE, width = 10, height = 500,
               imageOutput("image_ith_ens")),
           box(title = "Series Temporales de ITH WRF-ENS",
               collapsible = TRUE, width = 6, height = 800,
               imageOutput("plot_ith_ens"))
  )
  )
)
)

)

server <- function(input, output, session) {

dialogo al inicio de app

source(file = "./00_dialogue.R", local = TRUE)

abre archivos estáticos

sa <- read_sf("./shp_SA/", "SA")
logo <- readPNG("./www/logoSMN-75x80.png", native = TRUE)

UI según selección de dataset

output$variable <- renderUI({

if (input$time.tab1 == "01H")
{opts <- c("PP", "HR2", "T2", "dirViento10", "magViento10", "PSFC",
           "TSLB", "SMOIS")}

if (input$time.tab1 == "24H")
{opts <- c("Tmax", "Tmin")}

selectInput("variable",
            label = div(style = "color: black;", "Seleccione la variable del dataset:"), choices = opts)

})

UI del 2do TAB

output$tabSelection <- renderUI({

sidebarMenu(
  
  tags$br(),
  
  selectInput("time_ith", label = div(style = "color: black;", "Selección de hora de pronóstico WRF-ITH"),
              choices = paste0("(", sprintf("%02d", seq(1, 72, 1)), ")", " ",
                               seq(strptime(as.character(paste0(input$fecha.tab1, "T", input$ciclo.tab1)),
                                            format = "%Y-%m-%dT%H"),
                                   by = "hour",
                                   length.out = 72))),
  
  selectInput("estaciones", div(style = "color: black;", "Elija estación"),
              choices = c("Custom", "Sunchales", "Reconquista", "Ceres")),

  actionButton("ith_srs", "Grafica Serie ITH-WRF-DET", class = "btn-sm btn-success"))

})

file.for.points <- reactiveVal(NULL)

observeEvent(input$descarga, {
# elimina los archivos netcdf descargados
unlink(Sys.glob("*.nc"))

showNotification("La descarga de archivos se encuentra en proceso", duration = 7)
   
s <- get.wrf.files(anual = format(input$fecha.tab1, "%Y"),
              mes =format(input$fecha.tab1, "%m"),
              dia = format(input$fecha.tab1, "%d"),
              ciclo = input$ciclo.tab1,
              time = input$time.tab1)
   
showNotification("¡Listo!", duration = NULL)

file.for.points(substr(s$Key, 28, 58))

})

resp.2 <- eventReactive(input$Calcular_ith, {

tryCatch({
  # waiter en pantalla
  waiter::Waiter$new(html = spin_square_circle(), id = "image_ith")$show()

  folder.data <- "./"

  ith.calc <- ith.wrf.det(path.data = folder.data,
                          anual = format(input$fecha.tab1, "%Y"),
                          mes = format(input$fecha.tab1, "%m"),
                          dia = format(input$fecha.tab1, "%d"),
                          ciclo = input$ciclo.tab1)
  
  
}, error = function(e) {
  showNotification(paste("Error:", e$message), type = "error", duration = NULL)
  print(e)
  return(NULL)
})

})

----------------------------------------------------------------------------

OUTPUTS

OUTPUT TAB 1

OUTPUT PLOT METEOROLOGICAL VARIABLE

source(file = "./01a_plot_tab1.R", local = TRUE)

OUTPUT LEAFLET LOCATION

source(file = "./01b_leaflet_tab1.R", local = TRUE)

OUTPUT DATA TABLE METEOROLOGICAL VARIABLE

source(file = "./01c_table_tab1.R", local = TRUE)

----------------------------------------------------------------------------

OUTPUT TAB 2

OUTPUT MAP IMAGE ITH

source(file = "./02a_map_ith_tab2.R", local = TRUE)

OUTPUT TIME SERIES ITH

output$plot_ith <-renderPrint({print("SOLICITAR SERVICIO")})
source(file = "./02b_timeseries_ith_tab2.R", local = TRUE)

OUTPUT TIME SERIES ITH: NEW PRODUCT

source(file = "./02c_timeseries_ith_new_tab2.R", local = TRUE)

----------------------------------------------------------------------------

OUTPUT TAB 3

OUTPUT PROBABILITIES MAPS IMAGES & TIMESERIES ITH

source(file = "./03_map_timeseries_ith_tab3.R", local = TRUE)

----------------------------------------------------------------------------

}

shinyApp(ui = ui, server = server)

Could anyone help me to solve this??

Thank you,

  • Lorena

Presumably you upload the R scripts you source to the same directory as the main application?

Do you get an error message related to the crash (either in the browser or in the application log)?

Hello,

That is the problem, I do not get nothing in the log. I have already have some problem like this in the past. At that time I figured out like making some optimization of the code, but now I am not being able to do that.

At one momento I though that the problem could be that I didn't have a .Rproj file, I created but anyway I had the same problem.

It is like it continues working:

2025-07-16T16:26:42.214588+00:00 shinyapps[15068164]: [1] "nc_open: getting dimvar info for dim x"
2025-07-16T16:26:42.219154+00:00 shinyapps[15068164]: [1] "ncvar_get_inner: entering with (C-STYLE INTEGER ONLY) ncid= 2293760 varid= 15"
2025-07-16T16:26:42.223948+00:00 shinyapps[15068164]: [1] "ncvar_get_inner: following line is collapse_degen:"
2025-07-16T16:26:42.229150+00:00 shinyapps[15068164]: [1] TRUE
2025-07-16T16:26:42.233912+00:00 shinyapps[15068164]: [1] "ndims: 1"
2025-07-16T16:26:42.239806+00:00 shinyapps[15068164]: [1] "ncvar_get: varsize:"
2025-07-16T16:26:42.244965+00:00 shinyapps[15068164]: [1] 999
2025-07-16T16:26:42.250695+00:00 shinyapps[15068164]: [1] "ncvar_get_inner: start:"
2025-07-16T16:26:42.255604+00:00 shinyapps[15068164]: [1] 1
2025-07-16T16:26:42.260657+00:00 shinyapps[15068164]: [1] "ncvar_get_inner: count:"
2025-07-16T16:26:42.266469+00:00 shinyapps[15068164]: [1] 999
2025-07-16T16:26:42.271385+00:00 shinyapps[15068164]: [1] "ncvar_get: totvarsize: 999"
2025-07-16T16:26:42.276844+00:00 shinyapps[15068164]: [1] "ncvar_get_inner: getting var of type float id= 3"
2025-07-16T16:26:42.281961+00:00 shinyapps[15068164]: [1] "about to call Rsx_nc4_get_vara_double..."
2025-07-16T16:26:42.286742+00:00 shinyapps[15068164]: [1] "back from call to Rsx_nc4_get_vara_double..."
2025-07-16T16:26:42.291705+00:00 shinyapps[15068164]: [1] "ncvar_get_inner: C call returned 0"
2025-07-16T16:26:42.296629+00:00 shinyapps[15068164]: [1] "ncvar_get_inner: dim of directly returned array:"
2025-07-16T16:26:42.301717+00:00 shinyapps[15068164]: NULL
2025-07-16T16:26:42.306627+00:00 shinyapps[15068164]: [1] "ncvar_get_inner: will collapse degen dims if ndims > 0. ndims= 1 collapse_degen= TRUE precint= 3"
2025-07-16T16:26:42.311656+00:00 shinyapps[15068164]: [1] "count.nodegen: 999 Length of data: 999"
2025-07-16T16:26:42.316675+00:00 shinyapps[15068164]: [1] "ncvar_get: final dims of returned array:"
2025-07-16T16:26:42.321663+00:00 shinyapps[15068164]: [1] 999
2025-07-16T16:26:42.326633+00:00 shinyapps[15068164]: [1] "ncvar_get_inner: will now consider changing missing values to NA..."
2025-07-16T16:26:42.331360+00:00 shinyapps[15068164]: [1] "------------------------------"
2025-07-16T16:26:42.336281+00:00 shinyapps[15068164]: [1] "Here is new dim:"
2025-07-16T16:26:42.342061+00:00 shinyapps[15068164]: [1] "Global index= 3 name= x len= 999 unlim= FALSE id= 2 dimvarid= 15 units= m"
2025-07-16T16:26:42.346888+00:00 shinyapps[15068164]: [1] "------------------------------"
2025-07-16T16:26:42.351840+00:00 shinyapps[15068164]: [1] ".......nc_open: done processing dim x"
2025-07-16T16:26:42.357470+00:00 shinyapps[15068164]: [1] "nc_open: setting dim$ to:"
2025-07-16T16:26:42.362221+00:00 shinyapps[15068164]: [1] "time" "y" "x"
2025-07-16T16:26:42.366893+00:00 shinyapps[15068164]: [1] "nc_open: getting var info. Number of vars (INCLUDING dimvars)= 18"
2025-07-16T16:26:42.372111+00:00 shinyapps[15068164]: [1] "Working on group 1 (of 1 ), var 1 (of 18 ), name= PP"

But I have the app crashed:

Thank you

-Lorena

Are you saying that the log messages continue even after the user interface crashes?

Also, does this happen after an extended period during which the user is not interacting with the program (either because a very time-consuming calculation is taking place or because the user is busy doing something unrelated to the app)? A gray screen can mean that the application timed out and automatically disconnected from the server.

Yes, that it is what I say. Maybe there is a problem with the id of the tabs? I am checking now that.

Nono, it happens almost at the beggining of the app calculation.

  • Lorena

You might try adding a text output in the left margin and updating its contents periodically ("made it to line 103", "survived loading the data file", that sort of thing). The last visible message when it goes gray would give you some idea of about where in the code the problem is likely to be.

Hello,

Ok I solved it. There was a problem with the app parameters from shinyapps.io. I improved these parameters of the settings and now the app works just fine.

Thank you very much!

-Lorena

1 Like