tomroh / leaflegend

Provides extensions to the leaflet R package to customize legends with images, text styling, orientation, sizing, and symbology.
https://leaflegend.delveds.com
Other
34 stars 3 forks source link

Underscores in group layer functionality does not work for legends #75

Closed tomroh closed 11 months ago

tomroh commented 11 months ago
library(leaflet)
library(leaflegend)
leaflet() %>%
  addTiles() %>%
  addMarkers(data = quakes, group = 'mg_aadf_edges') %>%
  addLegendBin(
    pal = binPal,
    values = quakes$mag,
    position = 'bottomleft',
    title = 'addLegendBin',
    group = 'mg_aadf_edges'
  ) %>%
  addLayersControl(overlayGroups = c('mg_aadf_edges'),
    position = 'bottomright'
  )
tomroh commented 11 months ago

@marcusyoung, Regex considers "_" to be an alphanumeric character which is why it was not being cleansed for use with the javascript functionality.

marcusyoung commented 11 months ago

When I first read this thread I thought that was the issue and changed the group name just to a string with no special characters or spaces. Unfortunately that did not fix the problem.

tomroh commented 11 months ago

I can't reproduce that error. Changing underscore to "*" or removing all together both works for me.

tomroh commented 11 months ago

bf058cc0cbd347b391ef8a4dbe4bd07c361e6343

tomroh commented 11 months ago

When I first read this thread I thought that was the issue and changed the group name just to a string with no special characters or spaces. Unfortunately that did not fix the problem.

I isolated with this (on the "dev" branch now).

library(shiny)
library(leaflet)
library(leaflegend)
data(quakes)
ui <- fluidPage(
    sidebarLayout(
        sidebarPanel(
            checkboxInput('check', 'Show/Hide', value = TRUE)
        ),
        mainPanel(
           leaflet::leafletOutput('map')
        )
    )
)
server <- function(input, output) {
    output$map <- leaflet::renderLeaflet({
      binPal <- colorBin('Set1', quakes$mag)
      leaflet() %>%
        addTiles() %>%
        addMarkers(data = quakes, group = 'mg_aadf_edges') %>%
        addLegendBin(
          pal = binPal,
          values = quakes$mag,
          position = 'bottomleft',
          title = 'addLegendBin',
          group = 'mg_aadf_edges'
        ) %>%
        addLayersControl(overlayGroups = c('mg_aadf_edges'),
          position = 'bottomright'
        )
    })
    observe({
      if (input$check) {
        leafletProxy('map') |>
          showGroup('mg_aadf_edges')
      } else {
        leafletProxy('map') |>
          hideGroup('mg_aadf_edges')
      }

    })

}
shinyApp(ui = ui, server = server)