Shiny app works locally but error when published

Hi all,

I published my first shiny app yesterday that worked great until I tried to update the data file today. Now I get an error when I republish - 'The application failed to start (exited with code 1)'.

I thought it was a library/package issue based on the log, but I can't figure it out. Any help would be appreciated. Thanks.

Here is the log from shinyapps.io

2022-11-19T23:22:42.830964+00:00 shinyapps[7674988]: Function found when exporting methods from the namespace ‘raster’ which is not S4 generic: ‘update’
2022-11-19T23:22:42.830971+00:00 shinyapps[7674988]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
2022-11-19T23:22:42.830977+00:00 shinyapps[7674988]: Execution halted
2022-11-19T23:22:42.830980+00:00 shinyapps[7674988]: Shiny application exiting ...
2022-11-19T23:22:43.829757+00:00 shinyapps[7674988]: Running on host: 1354eb3b4c93
2022-11-19T23:22:43.829795+00:00 shinyapps[7674988]: Server version: 2022.09.0
2022-11-19T23:22:43.829812+00:00 shinyapps[7674988]: LANG: C.UTF-8
2022-11-19T23:22:43.829816+00:00 shinyapps[7674988]: Working directory: /srv/connect/apps/winter_bison_movements
2022-11-19T23:22:43.830084+00:00 shinyapps[7674988]: Running content using the current R environment
2022-11-19T23:22:43.836352+00:00 shinyapps[7674988]: R version: 4.2.1
2022-11-19T23:22:43.836365+00:00 shinyapps[7674988]: shiny version: 1.7.3
2022-11-19T23:22:43.836368+00:00 shinyapps[7674988]: httpuv version: 1.6.6
2022-11-19T23:22:43.836377+00:00 shinyapps[7674988]: rmarkdown version: 2.17
2022-11-19T23:22:43.836408+00:00 shinyapps[7674988]: knitr version: 1.40
2022-11-19T23:22:43.836412+00:00 shinyapps[7674988]: jsonlite version: 1.8.2
2022-11-19T23:22:43.836415+00:00 shinyapps[7674988]: RJSONIO version: (none)
2022-11-19T23:22:43.836447+00:00 shinyapps[7674988]: htmltools version: 0.5.3
2022-11-19T23:22:43.836457+00:00 shinyapps[7674988]: reticulate version: (none)
2022-11-19T23:22:43.836768+00:00 shinyapps[7674988]: Using pandoc: /opt/connect/ext/pandoc/2.16
2022-11-19T23:22:44.212549+00:00 shinyapps[7674988]: Starting R with process ID: '46'
2022-11-19T23:22:44.212907+00:00 shinyapps[7674988]: Shiny application starting ...
2022-11-19T23:22:50.320228+00:00 shinyapps[7674988]: Error in value[3L] : package or namespace load failed for ‘tmap’:
2022-11-19T23:22:50.320270+00:00 shinyapps[7674988]: Function found when exporting methods from the namespace ‘raster’ which is not S4 generic: ‘update’
2022-11-19T23:22:50.320275+00:00 shinyapps[7674988]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
2022-11-19T23:22:50.320279+00:00 shinyapps[7674988]: Execution halted
2022-11-19T23:22:50.320283+00:00 shinyapps[7674988]: Shiny application exiting ...

Here is my code:

setup -----------------------------------------

library(shiny)
library(shinyWidgets)
library(tmap)
library(sf)
library(lubridate)
library(tidyverse)

shapefiles <-
list(boundary = st_read('data/shapefiles/boundary.shp'),
north = st_read('data/shapefiles/north.shp')) %>%
set_names(
names(.) %>%
tolower())

spat_data <-
read_csv('data/move.csv') %>%
rename(lat = GPS.Latitude,
long = GPS.Longitude) %>%
st_as_sf(
coords = c('long', 'lat'),
crs = st_crs(4326)) %>%
st_transform(crs =
st_crs(shapefiles$boundary)) %>%
mutate(date =
as.Date(rtime)) %>%
set_names(
names(.) %>%
tolower())

ui --------------------------------------------

ui <-
fluidPage(

    titlePanel('Movements'),
    
    sidebarPanel(
        
        
        pickerInput(
            inputId = 'id_select', 
            label = 'ID:',
            choices = unique(spat_data$id),
            selected = unique(spat_data$id),
            options = list('actions-box' = TRUE),
            multiple = TRUE
        ),
        
       
        
        sliderInput(
            inputId = 'dates_slider',
            label = 'Date',
            min = as.Date('2022-10-01'),
            max = as.Date(max(spat_data$date)),
            value = c(
                as.Date(max(spat_data$date)) - 7,
                as.Date(max(spat_data$date))),
            dragRange = TRUE,
            animate = animationOptions(interval = 200),
            timeFormat = '%F')
    ),
    
    
    mainPanel(
        tmapOutput(outputId = 'movements_map')
    )
)

server ----------------------------------------

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

    movement_data <-
        reactive({
            spat_data %>%
                filter(id %in% input$id_select,
                       date >= input$dates_slider[1],
                       date <= input$dates_slider[2]) %>%
                group_by(id) %>%
                filter(n() > 1) %>% 
                summarise(do_union = FALSE) %>%
                st_cast('LINESTRING')
        })
    
    
    
    output$movements_map <-
        renderTmap({
            tm_shape(shapefiles$boundary,
                     name = 'boundary') +
                tm_polygons(alpha = 0,
                            lwd = 2) +
                tm_basemap(
                    c('Esri.WorldTopoMap',
                      'Esri.WorldImagery')) +
                tm_view(
                    bbox = shapefiles$boundary) +
                spat_data %>%
                group_by(id) %>%
                summarise(do_union = FALSE) %>%
                st_cast('LINESTRING') %>% 
                tm_shape(name = 'Trajectory') +
                tm_lines(col = 'id',
                         legend.col.show = FALSE,
                         lwd = 1.5,
                         style = 'cat',
                         palette = 'plasma',
                         popup.vars = c('id'),
                         zindex = 402)
        })
    
    
    observe({
        tmapProxy('movements_map', session, {
            if(!is.null(input$id_select)) {
                tm_remove_layer(402) + 
                    movement_data() %>% 
                    tm_shape(name = 'Trajectory') +
                    tm_lines(col = 'id',
                             legend.col.show = FALSE,
                             lwd = 1.5,
                             style = 'cat',
                             palette = 'plasma',
                             popup.vars = c('id'),
                             zindex = 402,
                             interactive = FALSE)
            } else {
                tm_remove_layer(402)
            }
        })
    }) 
    
}

The error based on logs is here. Did you try run the app in a fresh R session on your local first?

Encountered the same error here. Deploying the same app and the deployment changes from successful to fail. Neither re-deploying the app nor restarting the app in shinyapps.io solves the issue.

When I added some new code (no new libraries were added) 2 days ago, the deployment failed. There are no errors when I run the app with shiny::runApp('inst/app') on my computer.

The Shiny app: GitHub - Hong-Kong-Districts-Info/hktrafficcollisions: Shiny app dashboard of HK traffic collisions that result in injury. | 香港車禍傷亡資料庫:利用互動地圖和儀表版,將香港車禍位置和相關數據可視化。

Log in shinyapps.io

2022-11-23T13:31:55.254113+00:00 shinyapps[2682250]: Container event from container-7441477: start
2022-11-23T13:31:55.545132+00:00 shinyapps[2682250]: Running on host: 8a1f437dd710
2022-11-23T13:31:55.545151+00:00 shinyapps[2682250]: Server version: 2022.09.0
2022-11-23T13:31:55.545161+00:00 shinyapps[2682250]: LANG: C.UTF-8
2022-11-23T13:31:55.545165+00:00 shinyapps[2682250]: Working directory: /srv/connect/apps/trafficcollisions-dev
2022-11-23T13:31:55.545415+00:00 shinyapps[2682250]: Running content using the current R environment
2022-11-23T13:31:55.549788+00:00 shinyapps[2682250]: R version: 4.2.1
2022-11-23T13:31:55.549803+00:00 shinyapps[2682250]: shiny version: 1.7.3
2022-11-23T13:31:55.549815+00:00 shinyapps[2682250]: httpuv version: 1.6.6
2022-11-23T13:31:55.549821+00:00 shinyapps[2682250]: rmarkdown version: (none)
2022-11-23T13:31:55.549859+00:00 shinyapps[2682250]: knitr version: (none)
2022-11-23T13:31:55.549873+00:00 shinyapps[2682250]: jsonlite version: 1.8.3
2022-11-23T13:31:55.549877+00:00 shinyapps[2682250]: RJSONIO version: (none)
2022-11-23T13:31:55.549880+00:00 shinyapps[2682250]: htmltools version: 0.5.3
2022-11-23T13:31:55.549883+00:00 shinyapps[2682250]: reticulate version: (none)
2022-11-23T13:31:55.550132+00:00 shinyapps[2682250]: Using pandoc: /opt/connect/ext/pandoc/2.16
2022-11-23T13:31:55.823542+00:00 shinyapps[2682250]: Starting R with process ID: '26'
2022-11-23T13:31:55.823904+00:00 shinyapps[2682250]: Shiny application starting ...
2022-11-23T13:31:56.699886+00:00 shinyapps[2682250]: Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1; sf_use_s2() is TRUE
2022-11-23T13:32:00.727993+00:00 shinyapps[2682250]: Error in value[[3L]](cond) : package or namespace load failed for ‘tmap’:
2022-11-23T13:32:00.728031+00:00 shinyapps[2682250]:  Function found when exporting methods from the namespace ‘raster’ which is not S4 generic: ‘update’
2022-11-23T13:32:00.728038+00:00 shinyapps[2682250]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
2022-11-23T13:32:00.728043+00:00 shinyapps[2682250]: Execution halted
2022-11-23T13:32:00.728061+00:00 shinyapps[2682250]: Shiny application exiting ...
2022-11-23T13:32:02.125439+00:00 shinyapps[2682250]: Running on host: 8a1f437dd710
2022-11-23T13:32:02.125473+00:00 shinyapps[2682250]: Server version: 2022.09.0
2022-11-23T13:32:02.125480+00:00 shinyapps[2682250]: LANG: C.UTF-8
2022-11-23T13:32:02.125484+00:00 shinyapps[2682250]: Working directory: /srv/connect/apps/trafficcollisions-dev
2022-11-23T13:32:02.125725+00:00 shinyapps[2682250]: Running content using the current R environment
2022-11-23T13:32:02.130742+00:00 shinyapps[2682250]: R version: 4.2.1
2022-11-23T13:32:02.130767+00:00 shinyapps[2682250]: shiny version: 1.7.3
2022-11-23T13:32:02.130773+00:00 shinyapps[2682250]: httpuv version: 1.6.6
2022-11-23T13:32:02.130785+00:00 shinyapps[2682250]: rmarkdown version: (none)
2022-11-23T13:32:02.130789+00:00 shinyapps[2682250]: knitr version: (none)
2022-11-23T13:32:02.130794+00:00 shinyapps[2682250]: jsonlite version: 1.8.3
2022-11-23T13:32:02.130809+00:00 shinyapps[2682250]: RJSONIO version: (none)
2022-11-23T13:32:02.130845+00:00 shinyapps[2682250]: htmltools version: 0.5.3
2022-11-23T13:32:02.130851+00:00 shinyapps[2682250]: reticulate version: (none)
2022-11-23T13:32:02.131092+00:00 shinyapps[2682250]: Using pandoc: /opt/connect/ext/pandoc/2.16
2022-11-23T13:32:02.429094+00:00 shinyapps[2682250]: Starting R with process ID: '47'
2022-11-23T13:32:02.429462+00:00 shinyapps[2682250]: Shiny application starting ...
2022-11-23T13:32:03.366162+00:00 shinyapps[2682250]: Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1; sf_use_s2() is TRUE
2022-11-23T13:32:07.419017+00:00 shinyapps[2682250]: Error in value[[3L]](cond) : package or namespace load failed for ‘tmap’:
2022-11-23T13:32:07.419050+00:00 shinyapps[2682250]:  Function found when exporting methods from the namespace ‘raster’ which is not S4 generic: ‘update’
2022-11-23T13:32:07.419057+00:00 shinyapps[2682250]: Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
2022-11-23T13:32:07.419062+00:00 shinyapps[2682250]: Execution halted
2022-11-23T13:32:07.419069+00:00 shinyapps[2682250]: Shiny application exiting ...

My guess would be that these are package version / dependency issues.
I recommend tracking your projects package dependencies with renv;
It might be that rsconnect has failed to see it need to bundle 'raster' ? maybe adding a library(raster) in your code would help it out.

Updates: I updated the following spatial-related packages and the deploy error is resolved.

- s2          [1.1.0 -> 1.1.1]
- sf          [1.0-8 -> 1.0-9]
- sp          [1.5-0 -> 1.5-1]
- stars       [0.5-6 -> 0.6-0]
- terra       [1.6-17 -> 1.6-41]

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.