Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hckiang opened this issue Sep 19, 2024 · 1 comment
Open

Comments

@hckiang
Copy link

hckiang commented Sep 19, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@hckiang and others