Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legend is not saved in html #356

Open
vasya-paradiz opened this issue May 19, 2022 · 2 comments
Open

Legend is not saved in html #356

vasya-paradiz opened this issue May 19, 2022 · 2 comments

Comments

@vasya-paradiz
Copy link

vasya-paradiz commented May 19, 2022

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:
image

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

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:
image

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)

@dcooley
Copy link
Collaborator

dcooley commented Jul 14, 2022

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
	)

@dcooley
Copy link
Collaborator

dcooley commented Jul 14, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants