deckgl icon indicating copy to clipboard operation
deckgl copied to clipboard

In Shiny, deckgl_proxy and update_deckgl doesn't work with multiple maps

Open hckiang opened this issue 1 year ago • 1 comments

When there are two maps on the same Shiny app, deckgl_proxy seems to ignore the ID argument and plot stuff on the wrong map.

In the below code there are two maps. White dots should appear on the first map and red dots on the second; but I only see red dots on the first. It seems deckgl_proxy('rdeck2') has picked up rdeck1 instead.

library(shiny)
library(deckgl)

ui = fluidPage(
  deckglOutput("rdeck1"),
  deckglOutput("rdeck2"),
  actionButton("plot_it", "Plot it")
)

backend = function(input, output) {
  output$rdeck1 = renderDeckgl({ deckgl() |> add_basemap() })
  output$rdeck2 = renderDeckgl({ deckgl() |> add_basemap() })
  observeEvent(input$plot_it,{
    gauss = structure(rnorm(200,sd=0.01), dim=c(100,2))
    colnames(gauss) = c('lon','lat')
    gauss = t(t(gauss) + c(-122.43924751664561, 37.78713631379807))
    gauss = as.data.frame(gauss)
    print(gauss)
    ## First map should have white dots and second should have red
    deckgl_proxy('rdeck1') |> 
        add_scatterplot_layer(
          data = gauss,
          properties = list(getPosition = ~lon + lat,
                            getRadius   = 30,
                            getColor    = 'white'),
          id = 'scatter1') |>
        update_deckgl()
    deckgl_proxy('rdeck2') |> 
        add_scatterplot_layer(
          data = gauss,
          properties = list(getPosition = ~lon + lat,
                            getRadius   = 30,
                            getColor    = 'red'),
          id = 'scatter2') |>
        update_deckgl()
  })
}

shinyApp(ui, backend)

Is this a bug or am I using these functions wrong?

hckiang avatar Sep 19 '24 11:09 hckiang