I have a PWA r shiny app deployed to Heroku via docker. I use the Golem framework for the server functions and shinyMobile for the UI. The app works great around 99% of the time. However, sometimes the server is running BEFORE the UI function, and this triggers an error, as the UI needs to run before the server, amongst other reasons because I’m using shinyjs.
The error is triggered only the first time the app is app is startet, right after the “onStart” is run, as the server function misses objects generated via the UI function (some of the shinyjs$myfunction() etc). However, as Heroku requires an app restart once daily, I get the error around once a week. The user experiences an unresponsive app until it is restarted. Usually it occurs if a user has been using the app the before the app restart, and then opens the app again shortly after the app has been restarted.
Has anyone experienced a similar issue? I have provided a screendump from the log and sessionInfo():
Has anyone experienced such an error where the server is running before the UI? And any idea how to debug this rare behaviour?
How to force UI to run before server in shiny::runApp?
App is run via a function like this:
app = shinyApp(
ui = cookies::add_cookie_handlers(app_ui),
server = app_server,
onStart = function() {...}
)
Jun 25 02:01:34Z bbhneuro app/web.2 R version 4.1.2 (2021-11-01) -- "Bird Hippie" ## app is starting
Jun 25 02:01:34Z bbhneuro app/web.2 Copyright (C) 2021 The R Foundation for Statistical Computing
Jun 25 02:01:34Z bbhneuro app/web.2 Platform: x86_64-pc-linux-gnu (64-bit)
Jun 25 02:01:34Z bbhneuro app/web.2 R is free software and comes with ABSOLUTELY NO WARRANTY.
Jun 25 02:01:34Z bbhneuro app/web.2 You are welcome to redistribute it under certain conditions.
Jun 25 02:01:34Z bbhneuro app/web.2 Type 'license()' or 'licence()' for distribution details.
Jun 25 02:01:34Z bbhneuro app/web.2 Natural language support but running in an English locale
Jun 25 02:01:34Z bbhneuro app/web.2 R is a collaborative project with many contributors.
Jun 25 02:01:34Z bbhneuro app/web.2 Type 'contributors()' for more information and
Jun 25 02:01:34Z bbhneuro app/web.2 'citation()' on how to cite R or R packages in publications.
Jun 25 02:01:34Z bbhneuro app/web.2 Type 'demo()' for some demos, 'help()' for on-line help, or
Jun 25 02:01:34Z bbhneuro app/web.2 'help.start()' for an HTML browser interface to help.
Jun 25 02:01:34Z bbhneuro app/web.2 Type 'q()' to quit R.
Jun 25 02:01:34Z bbhneuro app/web.2 > options('shiny.port'=25157,shiny.host='0.0.0.0','golem.app.prod'=TRUE);shiny::runApp(appDir = 'inst/app')
Jun 25 02:01:34Z bbhneuro app/web.2 Loading required package: shiny
Jun 25 02:01:34Z bbhneuro app/web.2 ℹ Loading dynamicApp
Jun 25 02:01:36Z bbhneuro app/web.2 [1] "running onStart"
Jun 25 02:01:36Z bbhneuro app/web.2 Application detected via DATABASE_URL, now connected to Postgres
Jun 25 02:01:36Z bbhneuro app/web.2 downloading new file
[…](Downloading stuff etc )
Jun 25 02:01:54Z bbhneuro app/web.2 Listening on http://0.0.0.0:25157
Jun 25 06:07:48Z bbhneuro app/web.2 [1] "running server"
Jun 25 06:07:48Z bbhneuro app/web.2 1: shiny::runApp
Jun 25 06:07:48Z bbhneuro app/web.2 Warning: Error in observe: attempt to apply non-function
Jun 25 06:07:48Z bbhneuro app/web.2 1: shiny::runApp
Jun 25 06:07:49Z bbhneuro app/web.2 [1] "running server"
Jun 25 06:07:50Z bbhneuro app/web.2 1: shiny::runApp
Jun 25 06:07:50Z bbhneuro app/web.2 Warning: Error in observe: attempt to apply non-function
Jun 25 06:07:50Z bbhneuro app/web.2 1: shiny::runApp
Jun 25 06:07:50Z bbhneuro app/web.2 [1] "running server"
Jun 25 06:07:50Z bbhneuro app/web.2 1: shiny::runApp
Jun 25 06:07:50Z bbhneuro app/web.2 Warning: Error in observe: attempt to apply non-function
Jun 25 06:07:50Z bbhneuro app/web.2 1: shiny::runApp
Jun 25 06:07:51Z bbhneuro app/web.2 [1] "running server"
Jun 25 06:07:51Z bbhneuro app/web.2 1: shiny::runApp
Jun 25 06:07:51Z bbhneuro app/web.2 Warning: Error in observe: attempt to apply non-function
Jun 25 06:07:51Z bbhneuro app/web.2 1: shiny::runApp
Jun 25 06:07:51Z bbhneuro app/web.2 [1] "running ui"
Jun 25 06:07:51Z bbhneuro app/web.2 using cache for xlsx file
Jun 25 06:07:51Z bbhneuro app/web.2 New names:
Jun 25 06:07:51Z bbhneuro app/web.2 • `` -> `...8`
Jun 25 06:07:51Z bbhneuro app/web.2 [1] "running query to get new data"
Jun 25 06:07:53Z bbhneuro app/web.2 [1] "running server"
Jun 25 06:07:53Z bbhneuro app/web.2 from cache
[from here it works]
SessionInfo:
[1] dynamicApp_1.5.16 shiny_1.7.1
loaded via a namespace (and not attached):
[1] googledrive_2.0.0 ellipsis_0.3.2 ipc_0.1.3 cookies_0.2.1 rprojroot_2.0.3 base64enc_0.1-3 fs_1.6.0 rstudioapi_0.13
[9] roxygen2_7.1.2 listenv_0.8.0 urltools_1.7.3 remotes_2.4.2 bit64_4.0.5 golem_0.3.1 fansi_1.0.3 lubridate_1.7.9.2
[17] xml2_1.3.3 codetools_0.2-18 cachem_1.0.6 knitr_1.38 config_0.3.1 pkgload_1.2.4 jsonlite_1.8.4 rematch_1.0.1
[25] rpdf_0.0.1 RPostgres_1.3.1 compiler_4.1.2 httr_1.4.4 backports_1.4.1 assertthat_0.2.1 fastmap_1.2.0 gargle_1.2.0
[33] cli_3.6.1 authentication_0.1.1 later_1.3.0 htmltools_0.5.4 prettyunits_1.1.1 tools_4.1.2 glue_1.6.2 dplyr_1.0.7
[41] Rcpp_1.0.10 jquerylib_0.1.4 cellranger_1.1.0 vctrs_0.6.3 pdftools_3.4.0 writexl_1.3.1 xfun_0.37 stringr_1.4.0
[49] globals_0.16.2 ps_1.6.0 brio_1.1.3 testthat_3.1.2 rvest_1.0.2 mime_0.12 lifecycle_1.0.3 shinyvalidate_0.1.3
[57] googlesheets4_1.0.0 future_1.32.0 hms_1.1.1 promises_1.2.0.1 parallel_4.1.2 sodium_1.2.1 yaml_2.3.5 curl_5.0.0
[65] memoise_2.0.1 sass_0.4.5 triebeard_0.3.0 stringi_1.7.6 cyphr_1.1.4 desc_1.4.1 filelock_1.0.2 pkgbuild_1.3.1
[73] attempt_0.3.1 rlang_1.1.1 pkgconfig_2.0.3 commonmark_1.8.1 bitops_1.0-7 fontawesome_0.5.0 evaluate_0.15 shinyMobile_1.0.0
[81] emayili_0.7.9 purrr_1.0.2 calendar_0.0.1 htmlwidgets_1.5.4 bit_4.0.4 processx_3.8.0 tidyselect_1.1.2 parallelly_1.36.0
[89] logger_0.2.2 magrittr_2.0.3 R6_2.5.1 generics_0.1.1 base64url_1.4 txtq_0.2.4 DBI_1.1.1 pillar_1.7.0
[97] withr_2.5.0 RCurl_1.98-1.13 tibble_3.1.6 crayon_1.5.2 shinyWidgets_0.5.6 utf8_1.2.2 future.callr_0.8.1 rmarkdown_2.11
[105] usethis_2.1.5 readxl_1.3.1 qpdf_1.3.2 blob_1.2.2 callr_3.7.3 digest_0.6.31 xtable_1.8-4 tidyr_1.1.2
[113] httpuv_1.6.8 openssl_2.0.5 pool_0.1.6 bslib_0.4.2 dockerfiler_0.1.4 askpass_1.1 shinyjs_2.0.0