Legend is not saved in html
Hi, I create a map using add_grid, and I can see the legend in the viewer of R-studio but when I save it as html, the legend disappears.
Here is my code:
bb <- mapdeck(token = key,pitch = 20,
location = c(12.8262, 56.049), # middle point of Helsongborg map
# location = c(12.8262, 56.040), for pitch 30
zoom = 10.4,
style = mapdeck_style('streets')
) %>%
add_polygon( # adding shape layer
data = chi_shape
,fill_colour = "#49fc0350"
, stroke_colour = "#340163"
, stroke_width = 100
,update_view = FALSE
) %>% add_grid(data = as.data.frame(res3), lat = "lon", lon = "lat",
elevation = "p_tonns", elevation_scale = 4,
cell_size = 500,
elevation_function = "max",
colour_function = "max",
colour = "p_tonns",
layer_id = "tree",
extruded = T,
legend = T,
legend_options = list(title="Tons"),
update_view = F) %>%
add_title(title = paste0(i,", production by zone (tons)"))
file_html <- "file name"
saveWidget(bb, file_html)
I also tried to save html using mapshot but the result is the same.
So then I get this map in the viewer:

But when I open it in Chrome or Edge, I get this:

zooming-in / out or moving the map does not help, still no legend.
When I open Chrome console, there is no error, and it has the legend container:

In the same script I create another map using add_line, and in that case the legend works
I use mapdeck_0.3.4 R version 4.1.0 (2021-05-18) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19044)
Reprodicible example
library(mapdeck)
set_token(secret::get_secret("MAPBOX"))
df <- read.csv(paste0(
'https://raw.githubusercontent.com/uber-common/deck.gl-data/master/',
'examples/3d-heatmap/heatmap-data.csv'
))
df <- df[ !is.na(df$lng ), ]
mapdeck( style = mapdeck_style("dark"), pitch = 45 ) %>%
add_grid(
data = df
, lat = "lat"
, lon = "lng"
, cell_size = 5000
, elevation_scale = 50
, layer_id = "grid_layer"
, auto_highlight = TRUE
, legend = T
)
I've no idea why this happens. It looks like the .legendContent isn't being kept when exporting from RStudio to the browser. But I don't know why.