Warning: Error in google_dispatch: Invalid map parameter [No stack trace available] after using leafletProxy for polygons

Hello, this is my first time working with R shiny and I am attempting to integrate shiny features with a leaflet map I have made. The idea is that I would like to have radio buttons which toggle between four different polygons layers generated by shapefile data, and a slider which controls the opacity of the polygon layer. I used code from several different tutorials on shiny and leaflet but when I attempt to generate the map I get the following warning:

"Warning: Error in google_dispatch: Invalid map parameter
[No stack trace available]"

the panel with my buttons and slider appear but not my map. I believe this issue is with this section of my code:

opacityf <- reactive({
  
  opacity[opacity$value == input$slider, ]
  
})
       
  layerf <- reactive({
    
    switch(input$layer,
           countiesr = counties,
           regionsr = regions,
           triber = tribe,
           publicr = public,
           selected = NULL)
    
  })

  observe({
    
    leafletProxy(mapId = "Intensity_Map", data = layerf()) %>% 
      clear_polygons() %>%
      addPolygons(fillOpacity = opacityf(),
                  weight  = 1,
                  color = "purple4")
    
  })    }

I created a data frame with values between 0.0 and 1.0 for the opacity slider and I am attempting to direct shiny to change to opacity value to be whatever the slider value is. For the buttons I am trying to direct shiny to plot one of the four spatial polygon objects I created using the shapefiles. I believe I have a mistake in here somewhere but I cannot seem to figure out what it is.

Here is the rest of my code for reference:

`ui <- fluidPage(

titlePanel("Cyano-Toxin Concentration in Relation
to OEHHA Action Levels for Acute Toxicity in Dogs"),

sliderInput(inputId = "slider",
label = "Opacity",
min = 0,
max = 1,
value = NULL,
step = 0.1),

radioButtons(inputId = "layer",
label = "Map Layer",
choices = c("Counties" = "countiesr",
"Regional Boards" = "regionsr",
"Tribal Lands" = "triber",
"Public Lands" = "publicr")),

leafletOutput("Intensity_Map")
)

opacity <- data.frame(value = c(0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0))

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

output$Intensity_Map <- renderLeaflet({

leaflet() %>% setView(lat = 36.778259, lng = -119.417931, zoom = 5) %>% addTiles(group = "None") %>%
  addCircleMarkers(
    data = ws_ND,
    radius = 4,
    color = "grey",
    stroke = FALSE, fillOpacity = 0.7,
    label = ~as.character(label),
    popup = ~as.character(popup),
    group = "None Detected"
  )%>%
  addCircleMarkers(
    data = ws_M,
    radius = ws_M$Radius,
    color = ~pala(Percent.of.AL),
    stroke = FALSE, fillOpacity = 0.7,
    label = ~as.character(label),
    popup = ~as.character(popup),
    group = "Microcystin/Nod."
  )%>%
  addCircleMarkers(
    data = ws_C,
    radius = ws_C$Radius,
    color = ~palc(Percent.of.AL),
    stroke = FALSE, fillOpacity = 0.7,
    label = ~as.character(label),
    popup = ~as.character(popup),
    group = "Cylindrospermopsin"
  )%>%
  addCircleMarkers(
    data = ws_A,
    radius = ws_C$Radius,
    color = ~palb(Percent.of.AL),
    stroke = FALSE, fillOpacity = 0.7,
    label = ~as.character(label),
    popup = ~as.character(popup),
    group = "Anatoxin-a"
  )%>%
  addCircleMarkers(
    data = ws_S,
    color = "yellow",
    radius = 8,
    stroke = FALSE, fillOpacity = 0.7,
    label = ~as.character(label),
    popup = ~as.character(popup),
    group = "Saxitoxin"
  )%>%
  addLayersControl(
    overlayGroups = c("None Detected", "Microcystin/Nod.","Cylindrospermopsin","Anatoxin-a","Saxitoxin"),
    options = layersControlOptions(collapsed = FALSE),
    position = "topright"
  )%>%
  addLegend("bottomright", pal = palab, values = (labels = c("1. < 25%","2. 25% - 49%","3. 50% - 99%", "4. ≥ 100%")),
            title = "Microcystin/Nod.",
            opacity = 1,
            group = "Microcystin/Nod."
  )%>%
  addLegend("bottomright", pal = palbb, values = (labels = c("1. < 25%","2. 25% - 49%","3. 50% - 99%", "4. ≥ 100%")),
            title = "Anatoxin-a",
            opacity = 1,
            group = "Anatoxin-a"
  )%>%
  addLegend("bottomright", pal = palcb, values = (labels = c("1. < 25%","2. 25% - 49%","3. 50% - 99%", "4. ≥ 100%")),
            title = "Cylindrospermopsin",
            opacity = 1,
            group = "Cylindrospermopsin") })


opacityf <- reactive({
  
  opacity[opacity$value == input$slider, ]
  
})
       
  layerf <- reactive({
    
    switch(input$layer,
           countiesr = counties,
           regionsr = regions,
           triber = tribe,
           publicr = public,
           selected = NULL)
    
  })

  observe({
    
    leafletProxy(mapId = "Intensity_Map", data = layerf()) %>% 
      clear_polygons() %>%
      addPolygons(fillOpacity = opacityf(),
                  weight  = 1,
                  color = "purple4")
    
  }) }     shinyApp(ui, server)`

Any thoughts would be greatly appreaciated!

This topic was automatically closed 21 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.