How to plot map layer in shiny using leaflet?

Hi, I was wondering if someone can help me overlaying a map onto my leaflet map in Shiny?

A little context, my post history shows that i've been asking some help regarding geo-spatial plotting. I have a project where i am trying to overlay flood damage using a slider bar to represent elevation levels similar to <https://www.floodmap.net/>. But we have different objectives. We want to show how much flood damage a neighbourhood can occur in our city by rising elevation levels using a slider.

I just dont know what shiny output does this nor how to code it, if anyone can either show me or direct me to resources this will be highly appreciated. I am still learning Shiny, Leaflet, and sf. what i wrote so far is below, my greatest appreciation in advance.

library(shiny)
library(leaflet)

## This is the UI Section
ui <- fluidPage(
  leafletOutput("mymap"),
  sliderInput(inputId = "num", 
              label = "Water Levels in Metres", 
              value = 25, min = 1, max = 100),
  plotOutput("mapwithflood")
  )

## This is the Server Section
server <- function(input, output) {
  output$mymap <- renderLeaflet({
    leaflet() %>%
      addProviderTiles(providers$Esri.NatGeoWorldMap,
                       options = providerTileOptions(noWrap = TRUE)
      )
  })
  
  output$mapwithflood
  
}

## This is where the UI gets combined with the server
shinyApp(ui = ui, server = server)

What you describe is a nice, if not exactly entry level, modeling and visualization exercise.

You will find the basics of shiny integration described on RStudio's Leaflet pages.

For an example of a (very simple) map app built in Shiny using the well known & much loved North Carolina shapefile that comes with {sf} consider this example; it is turned inside out compared to your use case (the map is for clicking and text is for displaying information) but it is a start...

1 Like

Thank you kindly, i have looked at the leaflet documentation, but your post gave me some ideas.

I appreciate this, take care!

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.