'Issue add icon and legend with leaflet in r

I try to reduplicate the below code in r markdown, but meet: "Error in htmltools::tags$polygon(id = "diamond", points = draw_diamond(width = width, : attempt to apply non-function". how to solve this problem?

and code is from here: https://roh.engineering/posts/2021/05/map-symbols-and-size-legends-for-leaflet/

library(leaflet)
library(leaflegend)
data("quakes")
symbols <- makeSizeIcons(
  values = quakes$depth,
  shape = 'diamond',
  color = 'red',
  fillColor = 'red',
  opacity = .5,
  baseSize = 10
)

leaflet() %>%
  addTiles() %>%
  addMarkers(data = quakes,
             icon = symbols,
             lat = ~lat, lng = ~long) %>%
  addLegendSize(
    values = quakes$depth,
    color = 'red',
    fillColor = 'red',
    opacity = .5,
    title = 'Depth',
    shape = 'diamond',
    orientation = 'horizontal',
    breaks = 5)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source