walkerke / mapgl

R interface to Mapbox GL JS v3 and Maplibre GL JS
https://walker-data.com/mapgl
Other
91 stars 5 forks source link

Compare() in Shiny #20

Open isaacbain opened 4 months ago

isaacbain commented 4 months ago

Hello,

I can't seem to get compare() working in a Shiny app. I've tried to make a minimal reproducible example here. It gives the error: Warning in renderWidget(instance) : Ignoring explicitly provided widget ID "compare-container-db634"; Shiny doesn't use them.

# Load libraries
library(shiny)
library(mapgl)

# Define UI
ui <- fluidPage(
  titlePanel("Map Comparison"),
  mainPanel(
    mapboxglOutput("compare_map", height = "800px")
  )
)

# Define Server logic
server <- function(input, output, session) {

  output$compare_map <- renderMapboxgl({
    m1 <- mapboxgl(style = mapbox_style("light"))
    m2 <- mapboxgl(style = mapbox_style("dark"))

    # Use the compare function as documented
    compare(m1, m2)
  })
}

# Run the application
shinyApp(ui = ui, server = server)
walkerke commented 4 months ago

compare() doesn't work in Shiny yet. Because of how it's structured it's technically a separate HTMLwidget that would need its own render function. I'd like to get this working eventually!

research-flow commented 3 weeks ago

Hey, I would love to get this working, however I am not really familiarised with rendering HTMLwidgets yet. Are there any updates on this function? Thanks!