Shiny App Disconnected From Server When Selecting an Input and Popups Not Working

Hello

I have created this shiny app:

https://garrettrsmith.shinyapps.io/RIB_shinyapp/

When I run it locally I can switch between the years in the SelectInput drop-down menu no problem. When I deploy the app onto my shinyapps.io account and switch between years in the SelectInput drop-down menu the map goes gray and I get the "Disconnected from the server. Reload" icon.

I also cannot seem to get the popups to work for each of the circle makers.

Here is a dummy dataset that is a smaller subset of the original and the code:

site <- c("Browns Canyon", "Hancock", "Monarch Crest")
 lat <- c("38.76210", "38.70581", "38.49185")
 long <- c("-105.9776", "-106.3405", "-106.3171")
 agency <- c("BLM", "USFS", "BLM")
 Total2016 <- ("353", "1112", "9875")
 Total2017 <- c("0", "138", "7435")
 Total2018 <- c("201", "145", "16448")
 Total2019 <- c("153", "0", "9655")
 alluse <- data.frame(site, lat, long, Total2016, Total2017, Total2018, Total2019)
    
    ui <- navbarPage(
   "Chaffee County Trail Counts", id = "nav",
   tabPanel("Trail Count Map By Year", div(class = "outer",
                                  tags$head(
                                  includeCSS("www/style.css"),
                                  includeScript("www/gomap.js")),
                                   leafletOutput("UsageMap", width = "100%", height = "100%"),
                                   absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
                                                 draggable = TRUE, top = 70, left = "auto", right = 20, bottom = "auto",
                                                 width = 330, height = "auto",
                                                 
                                                 h2("Trailhead Explorer"),
                                                 
                                                 selectInput("year", label = h4("Year:"),
                                                             choices = c("2016" = "Total2016",
                                                                         "2017" = "Total2017",
                                                                         "2018" = "Total2018",
                                                                         "2019" = "Total2019"),
                                                             selected = "", width = "90%", multiple = FALSE),
                                                 
                                                 tags$div(id="cite",
                                                          'Data provided by USFS and BLM and compiled for 
                                                          Chaffee County Recreation in Balance')
                                   ))),

          tabPanel("Trail Count Database",
         
         DT::dataTableOutput("trailheadtable")
       ))

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

    output$UsageMap <- renderLeaflet({
    leaflet() %>% 
    addProviderTiles("Esri.WorldTopoMap") %>%
   setView(lng = -106.183908, lat = 38.766663, zoom = 9)
   })

 observe({
 yearcolorBy <- input$year
colorData <- alluse[[yearcolorBy]]
radius <- sqrt(alluse[[yearcolorBy]]) * 30
pal <- colorBin("viridis", colorData, 10, pretty = FALSE)

leafletProxy("UsageMap", data = alluse) %>%
clearShapes() %>%
addCircles(~long, ~lat, radius = radius, layerId =~ site,
           stroke = FALSE, fillOpacity = 0.4, fillColor = pal(colorData)) %>%
addLegend("bottomleft", pal = pal, values = colorData, title = yearcolorBy, layerId = "colorLegend")

})

showTrailheadPopup <- function(site, lat, long) {
selectedSite <- alluse[alluse$site == site,]
                          content <- as.character(tagList(
                            tags$h4("Trailhead:", as.character(selectedSite$site)),
                            tags$h3("Agency:", as.character(selectedSite$agency)),
                            tags$br(),
                            sprintf("Total 2016: %s", as.numeric(selectedSite$Total2016)), tags$br(),
                            sprintf("Total 2017: %s", as.numeric(selectedSite$Total2017)), tags$br(),
                            sprintf("Total 2018: %s", as.numeric(selectedSite$Total2018)), tags$br(),
                            sprintf("Total 2019: %s", as.numeric(selectedSite$Total2019))
                          ))
                          leafletProxy("UsageMap") %>% addPopups(lat, long, content, layerId = site)
    }

observe({
leafletProxy("UsageMap") %>% clearPopups()
event <- input$map_shape_click
if (is.null(event))
return()

isolate({
showTrailheadPopup(event$id, event$lat, event$long)
})
})

output$trailheadtable <- DT::renderDataTable({
alluse %>%
filter(is.null(input$site)) %>%
mutate(Action = paste('<a class="go-map" href="" data-lat="', lat, 
                      '" data-long="', long, '" data-trailhead="', site, '"><i class="fa fa-crosshairs"></i></a>',    
 sep=""))
 action <- DT::dataTableAjax(session, alluse, outputId = "trailheadtable")

 DT::datatable(alluse, options = list(ajax = list(url = action)), escape = FALSE)

 })

}

I am also having an issue with the popups not working.

Thank you for any help you can provide.

Hi,

Issues with Shiny code can stem from both the reactive Shiny code itself or the regular R code used in the functions. In order for us to help you with your question, please provide us a minimal reprocudible example (Reprex) where you provide a minimal (dummy) dataset and code that can recreate the issue. One we have that, we can go from there. For help on creating a Reprex, see this guide:

Good luck!
PJ

Hello

Thank you for the response. I completely forgot to include a dataframe that mimics the larger dataframe that I am working with.

I am also including my shinyapps.io log below:

2019-12-14T12:57:50.325660+00:00 shinyapps[1598221]: knitr version: (none)
2019-12-14T12:57:50.325661+00:00 shinyapps[1598221]: jsonlite version: 1.6
2019-12-14T12:57:50.325672+00:00 shinyapps[1598221]: RJSONIO version: (none)
2019-12-14T12:57:50.325864+00:00 shinyapps[1598221]: Using pandoc at /opt/connect/ext/pandoc2
2019-12-14T12:57:50.508011+00:00 shinyapps[1598221]: Using jsonlite for JSON processing
2019-12-14T12:57:50.566502+00:00 shinyapps[1598221]:
2019-12-14T12:57:50.325691+00:00 shinyapps[1598221]: htmltools version: 0.4.0
2019-12-14T12:57:50.566504+00:00 shinyapps[1598221]: Starting R with process ID: '254'
2019-12-14T12:57:50.893391+00:00 shinyapps[1598221]:
2019-12-14T12:57:50.893393+00:00 shinyapps[1598221]: Attaching package: ‘dplyr’
2019-12-14T12:57:50.893393+00:00 shinyapps[1598221]:
2019-12-14T12:57:50.894066+00:00 shinyapps[1598221]: The following objects are masked from ‘package:stats’:
2019-12-14T12:57:50.894066+00:00 shinyapps[1598221]:
2019-12-14T12:57:50.894067+00:00 shinyapps[1598221]: filter, lag
2019-12-14T12:57:50.894067+00:00 shinyapps[1598221]:
2019-12-14T12:57:50.895074+00:00 shinyapps[1598221]:
2019-12-14T12:57:50.952427+00:00 shinyapps[1598221]:
2019-12-14T12:57:50.895072+00:00 shinyapps[1598221]: The following objects are masked from ‘package:base’:
2019-12-14T12:57:50.895073+00:00 shinyapps[1598221]:
2019-12-14T12:57:50.895073+00:00 shinyapps[1598221]: intersect, setdiff, setequal, union
2019-12-14T12:57:50.952429+00:00 shinyapps[1598221]: Listening on http://127.0.0.1:40376
2019-12-14T12:57:55.646156+00:00 shinyapps[1598221]: Warning: Error in : 'is_weakref' is not an exported object from 'namespace:rlang'
2019-12-14T12:57:55.651640+00:00 shinyapps[1598221]: [No stack trace available]
2019-12-14T12:57:55.651907+00:00 shinyapps[1598221]: Error : 'is_weakref' is not an exported object from 'namespace:rlang'
2019-12-14T22:18:20.751683+00:00 shinyapps[1598221]: Server version: 1.7.8-7
2019-12-14T22:18:20.751719+00:00 shinyapps[1598221]: LANG: en_US.UTF-8
2019-12-14T22:18:20.751720+00:00 shinyapps[1598221]: R version: 3.4.2
2019-12-14T22:18:20.751721+00:00 shinyapps[1598221]: shiny version: 1.4.0
2019-12-14T22:18:20.751721+00:00 shinyapps[1598221]: httpuv version: 1.5.2
2019-12-14T22:18:20.751727+00:00 shinyapps[1598221]: rmarkdown version: (none)
2019-12-14T22:18:20.751728+00:00 shinyapps[1598221]: knitr version: (none)
2019-12-14T22:18:20.751744+00:00 shinyapps[1598221]: jsonlite version: 1.6
2019-12-14T22:18:20.751943+00:00 shinyapps[1598221]: Using pandoc at /opt/connect/ext/pandoc2
2019-12-14T22:18:20.751751+00:00 shinyapps[1598221]: RJSONIO version: (none)
2019-12-14T22:18:20.751763+00:00 shinyapps[1598221]: htmltools version: 0.4.0
2019-12-14T22:18:21.053684+00:00 shinyapps[1598221]: Using jsonlite for JSON processing
2019-12-14T22:18:21.128039+00:00 shinyapps[1598221]:
2019-12-14T22:18:21.128043+00:00 shinyapps[1598221]: Starting R with process ID: '24'
2019-12-14T22:18:21.668556+00:00 shinyapps[1598221]:
2019-12-14T22:18:21.668558+00:00 shinyapps[1598221]: Attaching package: ‘dplyr’
2019-12-14T22:18:21.668559+00:00 shinyapps[1598221]:
2019-12-14T22:18:21.669453+00:00 shinyapps[1598221]: The following objects are masked from ‘package:stats’:
2019-12-14T22:18:21.669454+00:00 shinyapps[1598221]:
2019-12-14T22:18:21.670884+00:00 shinyapps[1598221]:
2019-12-14T22:18:21.752414+00:00 shinyapps[1598221]:
2019-12-14T22:18:21.752416+00:00 shinyapps[1598221]: Listening on http://127.0.0.1:38215
2019-12-14T22:18:21.669455+00:00 shinyapps[1598221]: filter, lag
2019-12-14T22:18:21.669455+00:00 shinyapps[1598221]:
2019-12-14T22:18:21.670882+00:00 shinyapps[1598221]: The following objects are masked from ‘package:base’:
2019-12-14T22:18:21.670883+00:00 shinyapps[1598221]: intersect, setdiff, setequal, union
2019-12-14T22:18:21.670883+00:00 shinyapps[1598221]:

I do not know how to decipher this.

Again thank you for responding to my original query and for providing some helpful things that I can do to make it easier on the community to help with my problem.

Hi,

Thanks for the updates, but I still can't run it properly.

Your map is dependent on an offline map gomap.js I don't have (and style.css).
Also I needed to uncomment the numerical values in your data frames and add the libraries and final ShinyApp line of code to merge UI and Server. Make sure in future to test the code you share by pasting it in a new R instance (to check the code is not relying on loaded data or additional files).

The only error I really see in the log file is the Error : 'is_weakref' is not an exported object from 'namespace:rlang' which seems to suggest that either the correct package is not loaded or needs to be updated. I'm not sure about that though...

Is this the error you get when the app freezes?

PJ