SymbolixAU / mapdeck

R interface to Deck.gl and Mapbox
https://symbolixau.github.io/mapdeck/articles/mapdeck.html
362 stars 40 forks source link

Legend doesnt show up when using add_grid in RMarkdown file #348

Closed samatt closed 1 year ago

samatt commented 2 years ago

Describe the bug When I run the following code in an RScript it works just find and produces a map with a legend in the bottom left corner as I would expect. When I run the exact same code in an RMarkdown file the legend no longer appears. When I inspect the generated html the legendContainerhtmlwidget is empty, suggesting that there is some problem with how the html is generated, rather than something to do with styling.

To Reproduce Here is the code i run.

mapdeck(token = MAPBOX_ACCESS_TOKEN, style = mapdeck_style("satellite-streets")) %>%
  add_grid(
    data = data,
    lat = "lat",
    lon = "lon",
    colour_function = "sum",
    colour = "count",
    cell_size = 150,
    colour_range = colourvalues::colour_values(1:6, palette = "purd", alpha = 0.5),
    layer_id = "grid_layer",
    extruded = FALSE,
    legend = TRUE,
    focus_layer = TRUE,
    legend_options = list(title = "My Label")
  )

The data is really simple, just the following columns lat,lon,count.

Thanks in advance!

dcooley commented 2 years ago

Using the example data in ?add_grid() worked for me.

Screenshot 2021-11-29 at 10 51 44 am

Can you try this and see what happens for you?

samatt commented 2 years ago

Thanks for the suggestion I just ran the same code and dont get a legend

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( token = MAPBOX_API_KEY, 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,
  legend_options = list(tite = "Test Legend")
)

image Any ideas on what else I can try?

dcooley commented 2 years ago

A few questions:

  1. Is that within a markdown document?
  2. Which browser are you using
    1. a. Are there any javascript errors in the console? (in Chrome press Ctrl+Shift+C, then select the 'console' tab)
  3. Which version of mapdeck