1 year ago

#72555

test-img

yearntolearn

load data and set up custom projection in R Shiny (leaflet)

I would like to load data and set up a custom projection in R Shiny. I am able to load the data but cannot get the projection right (ESPG:26916). I have searched but am not sure what I have missed. Help much appreciated.

Here is the code I have

library(leaflet)
library(tidyverse)

ui <- fluidPage(
  column(
    width = 4,
    leafletOutput("mymap", width = 1400, heigh = 700)),
  p(),
  fileInput("in_file", "Input file:",
            accept=c("txt/csv", "text/comma-separated-values,text/plain", ".csv", "Decimal seperator")),
  actionButton("upload_data", "Visualize New points")#,
)

server <- function(input, output, session) {
  visualize <- reactive({
    if(input$upload_data==0) {
      return(NULL)
    }
    df <- read.csv(input$in_file$datapath, 
                   sep = ',',
                   header = TRUE,
                   quote = "#",
                   row.names = NULL)
    epsg26916 <- leafletCRS(
      crsClass = "L.Proj.CRS",
      code = 'EPSG:26916',
      
      proj4def = "+proj=utm +zone=16 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs",
      resolutions = 2^(15:-1)
    )
    
    
    return(leaflet(df,
                   options = leafletOptions(crs = epsg26916)
    ) %>%
      addProviderTiles(providers$Esri.WorldImagery,
                       options = providerTileOptions(noWrap = TRUE)) %>%
      setView(-85.39310209, 42.41438242, zoom = 16) %>%
      addCircleMarkers(~easting, ~northing, 
                       group = "my data",
                       weight = 1, fillOpacity = 0.7, radius = 3) %>%
      addLayersControl(overlayGroups = c("my data"))
    )
  })
  
  
  output$mymap <- renderLeaflet({
    visualize()
  })
}

shinyApp(ui, server)

shiny

leaflet

projection

0 Answers

Your Answer

Accepted video resources