walkerke / mapgl

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

Compare() in Shiny #20

Open isaacbain opened 1 month ago

isaacbain commented 1 month 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 1 month 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!