How add search box in leaflet?

Hi community

I'm need add a search box forACCENUMB. The code run but the search box don't run well.

library(tidyverse)
library(leaflet) 

NUM_ORIGCTY <- DFINAL$ORIGCTY %>% unique() %>% length()
Names_ORIGCTY <- DFINAL$ORIGCTY %>% unique()
Colores <- c("#5F11A3","#FF1300","#0F629C", "#F3E908")

pal <- colorFactor(
  palette = c("#5F11A3","#FF1300","#0F0065", "#F70079"),
  domain = DFINAL$ORIGCTY)


m3<-leaflet() %>%
  addTiles() %>%
  #setView(lng=-76.5, lat=2.2 , zoom=9) %>%
  addCircles(data=DFINAL,
    lng = ~LONGITUDE, 
    lat=~LATITUDE,
    color=~pal(ORIGCTY),
    fillOpacity =20,
    weight =9,
    popup = paste("<h3 style='color:#002053'> DATOS </h3>",
      "<b style='color:#214173'> ACCENUMB:</b>",DFINAL$ACCENUMB,"<br>",
      "<b style='color:#214173'> PAIS:</b>",DFINAL$ORIGCTY,"<br>",
      "<b style='color:#214173'> LATITUD:</b>",DFINAL$LATITUDE,"<br>",
      "<b style='color:#214173'> LONGITUD:</b>",DFINAL$LONGITUDE,"<br>"),
    group = ~ ORIGCTY) %>%
  
  addMarkers(data=DFINAL,
    lng = ~LONGITUD_NEW, 
    lat=~LATITUD_NEW,
    group = 'ACCENUMB',
    popup = paste("<h3 style='color:#008000'> DATOS </h3>",
      "<b style='color:#AAAA39'> ACCENUMB:</b>",DFINAL$ACCENUMB,"<br>",
      "<b style='color:#AAAA39'> PAIS:</b>",DFINAL$ORIGCTY,"<br>",
      "<b style='color:#AAAA39'> LATITUD:</b>",DFINAL$LATITUD_NEW,"<br>",
      "<b style='color:#AAAA39'> LONGITUD:</b>",DFINAL$LONGITUD_NEW,"<br>")) %>% 
  
  addLegend(data = DFINAL,'bottomright', pal = pal,
    values = ~ ORIGCTY, title = "PAISES",
    opacity = 0.8,group = "Leyenda")  %>% 
  
  addLayersControl(overlayGroup=Names_ORIGCTY,
    options = layersControlOptions(collapsed=F)) %>%
  
  addResetMapButton() %>%
  
  #####
addSearchFeatures(
  targetGroups = 'ACCENUMB', # group should match addMarkers() group
  options = searchFeaturesOptions(
    zoom=12, openPopup = TRUE, firstTipSubmit = TRUE,
    autoCollapse = TRUE, hideMarkerOnCollapse = TRUE
  )
) %>%
  addControl("<P><B>Hi!</B> Search for ...<br/>
              <ul><li>ACESSION NAME</li>",
    position = 'topleft')
  
m3

DATA

DFINAL<-
structure(list(
ACCENUMB = c("G 2771", "G 2771A", "G 6386", "G 7225", "G 7225A", "G 7253B", "G 7479", "G 7479A", "G 7479B", "G 7479C"), 
LATITUDE = c(21.09, 22.09, 18.88, -13.67, -13.21, 2.67, 16.32, 18.4, 15.32, 12.32), 
LONGITUDE = c(-104.42, -104.42, -99.15, -72.88, -72.88, -75.98, -99.82, -99.82, -99.82, -99.82),
ORIGCTY = c("MEX", "MEX", "MEX", "PER", "PER", "COL", "MEX", "MEX", "MEX", "MEX"), 
LATITUD_NEW = c(21.17, 21.17, 18.9, -13.67, -13.67, 2.68, 18.32, 18.32, 18.32, 18.32),
LONGITUD_NEW = c(-104.37, -102.37, -99.15, -72.89, -75.89, -75.99, -99.82, -94.82, -93.82, -91.82
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-10L))

The idea is make more easy find any ACCENUMB . Because are 1500 unique name.

Im find the solution with library(inlmisc).

library(inlmisc) 
library(leaflet)

m2 <- leaflet() %>% 
  addTiles() %>% 
  addMarkers(label = ~ACCENUMB, popup = paste("<h3 style='color:#008000'> DIMARY</h3>",
    "<b style='color:#bb042b'> ACCESION: </b>",DFINAL$ACCENUMB, "<br>",
    "<b style='color:#bb042b'> LATITUD: </b>",DFINAL$LATITUD_NEW, "<br>",
    "<b style='color:#bb042b'> LONGITUD:</b>",DFINAL$LONGITUD_NEW,"<br>"), 
    clusterId = "cluster",
    group = "marker", lng = ~ LONGITUD_NEW,  lat= ~ LATITUD_NEW, data= DFINAL) %>% 
  
  AddSearchButton( group = "marker", zoom = 20,  # For add search box in the map.
    textPlaceholder = "Search accesion name...") %>%
  
  addCircles(label = ~ACCENUMB,
    data=DFINAL,
    lng = ~LONGITUDE, 
    lat=~LATITUDE,
   # color=~pal(ORIGCTY),
    fillOpacity = 1,
    weight =8,
    popup = paste("<h3 style='color:#008000'> ORACLE</h3>",
      "<b style='color:#bb042b'> ACCESION: </b>",DFINAL$ACCENUMB , "<br>",
      "<b style='color:#bb042b'> LATITUD: </b>",DFINAL$LATITUDE, "<br>",
      "<b style='color:#bb042b'> LONGITUD:</b>",DFINAL$LONGITUDE,"<br>"))

m2

:muscle:t4:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.