1

I would like to use the mapview package - it is quite fast - in shiny. In order to render the mapview object the @map trick works like a charm.

However, as opposed to ggplot2, making the mapview_leaflet object reactive, is quite complicated. In my shiny app, I would like to make the color palette interactive. Is that possible?

library(mapview)
library(shiny)

server <- function(input, output) {
  output$test <- renderLeaflet({
    req(input$obs)
    rws <- input$obs
    mapview(breweries91[1:rws,])@map
  })
}

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      sliderInput("obs", "Number of observations:", min = 1, max = nrow(breweries91@data), value = nrow(breweries91@data))
    ),
    mainPanel(
      leafletOutput('test')
    )
  )
)

shinyApp(ui = ui, server = server)
Hack-R
  • 22,422
  • 14
  • 75
  • 131
Pindar
  • 51
  • 6
  • 3
    Welcome to Stack Overflow! This would be a ***much*** better question if you showed a Minimal, Complete, Verifiable reproducible example app and then describe or show how you need it modified to do what you want. – Hack-R Jul 01 '18 at 21:12
  • the code is taken from https://github.com/r-spatial/mapview/issues/58 It makes the data set used reactive. – Pindar Jul 02 '18 at 21:41
  • I think that helps. You might want to add the line to load the data used in that code (I think it's builtin to some package) and describe your desired output vs what this generates a bit more. – Hack-R Jul 02 '18 at 21:44
  • The mapview function has the argument col.regions. Perhaps its enough to integrate this additional argument in combination with a `radioButton` – Pindar Jul 02 '18 at 21:46
  • I would give it a try – Hack-R Jul 02 '18 at 21:49

1 Answers1

0

I can confirm, that by making the input data and hence the mapview object reactive, mapview and shiny work like a charm with the @map hack. In conjunction with the leaflet-easyprint plugin it is a very useful tool for creating and exporting maps.

Pindar
  • 51
  • 6