0

I'm trying to use observeEvent() to change the Mapview's x argument to new data. I'd normally just use clearShapes() then addPolygons(), but need the zcol etc. arguments.

I'd like to do something similar to the following:

server <- function(input, output) {
  output$DisplayMap <- renderLeaflet(
    mapview(first_data, zcol = coolCol, color = brewer.pal(12, "Set3") %>%
      addControl(actionButton("Next", ">"), position = "topright")
  )
  observeEvent(input$Next, {
    output$DisplayMap$x <- next_data  # This doesn't work
  })
}

I realise there's 2 issues at play (an interface to change the variable and a means to do so), and one of them probably needs React in some form or another

Warpspace
  • 3,215
  • 3
  • 21
  • 24
  • Can you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? – bretauv Jan 28 '22 at 07:45
  • I wish I could. This is behaviour I don't yet know how to achieve, so I'm not sure how to produce a reproducible example. I was thinking of snipping my half-implemented code, but I suspect that will produce some confusion and off-topic discussions as to other parts of my code – Warpspace Jan 29 '22 at 07:19

1 Answers1

1

I think it's not possible to modify output like this (but indeed, it will be easier with MRE).

You should think about something like this:

server <- function(input, output) {

  my_data <- reactiveVal(data.frame(a = 1, b = 2))

  output$DisplayMap <- renderLeaflet(
    mapview(my_data()[[input$Next]], zcol = coolCol, color = brewer.pal(12, "Set3") %>%
      addControl(actionButton("Next", ">"), position = "topright")
  )
}

Assuming input$Next is a name of column which user can choose in GUI. This is just to show you an idea. Send MRE if you still need a help and I can edit this answer.

gss
  • 1,334
  • 6
  • 11
  • Ah, I see where you're going with that. Yes, that's what I was looking for, minus the `Next` value I need to get somehow. Would it be possible to edit your answer to include how I could add a hidden input value. That would make it complete. I hear such a thing is possible – Warpspace Jan 29 '22 at 07:25
  • I suppose the hidden input value is out of scope, so I've accepted this answer. The value DOES change, which is what I wanted – Warpspace Jan 31 '22 at 23:51