Place the non-geographic mapview object in the Shiny app

My main question is how to put a PNG or mapview object in a brilliant application to enable the placement of markers over it.

enter image description here

I have 15 non-geographic mapview objects such as PNGs that have been converted to mapview objects using the following code with another question here :

library(raster)
library(png)
library(mapview)

ohs<-data.frame(OHS_no=c(1001:1010), x=runif(10, 0, 1), y = runif(10, 0, 0.8), AGE = c(4, 15, 15, 43, 5, 50, 67, 77, 77, 28))
web_img <- "http://i.stack.imgur.com/8aSe9.png"

png <- readPNG(readBin(web_img, "raw", 1e6))

rst_blue <- raster(png[, , 1])
rst_green <- raster(png[, , 2])
rst_red <- raster(png[, , 3])

img <- brick(rst_red, rst_green, rst_blue)

m <- viewRGB(img)
abs(cbind(rnorm(40), rnorm(40)))
m@map %>% addMarkers(lng = ohs$x, lat = ohs$y)

I'm trying to create a Shiny application to put it all together, but am stuck in the renderLeaflet command and not sure how to place the m @map object in the application. Basically lower functionality with a map object as a flyer.

library(shiny)
library(leaflet)
ohs<-data.frame(OHS_no=c(1001:1010), x=runif(10, 0, 1), y = runif(10, 0, 0.8))
r_colors <- rgb(t(col2rgb(colors()) / 255))
names(r_colors) <- colors()

ui <- fluidPage(
 leafletOutput("mymap"),
 p(),

)

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



  output$mymap <- renderLeaflet({
   leaflet() %>%
      addProviderTiles("Stamen.TonerLite",
                       options = providerTileOptions(noWrap = TRUE)
      ) %>%
      addMarkers(lng = ohs$x, lat = ohs$y)
  })
}

shinyApp(ui, server)
0
source share
1 answer

:

library(shiny)
library(mapview)
library(png)
library(raster)

ohs<-data.frame(OHS_no=c(1001:1010), x=runif(10, 0, 1), y = runif(10, 0, 0.8))
r_colors <- rgb(t(col2rgb(colors()) / 255))
names(r_colors) <- colors()

ui <- fluidPage(
  leafletOutput("mymap"),
  p()

)

server <- function(input, output, session) {
  web_img <- "http://i.stack.imgur.com/8aSe9.png"

  png <- readPNG(readBin(web_img, "raw", 1e6))

  rst_blue <- raster(png[, , 1])
  rst_green <- raster(png[, , 2])
  rst_red <- raster(png[, , 3])

  img <- brick(rst_red, rst_green, rst_blue)

  m <- viewRGB(img)

  output$mymap <- renderLeaflet({
    m@map %>%
      addMarkers(lng = ohs$x, lat = ohs$y)
  })
}

shinyApp(ui, server)

leaflet() m@map ( ). , , .

+2

Source: https://habr.com/ru/post/1648487/


All Articles