-
Notifications
You must be signed in to change notification settings - Fork 40
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
Layers fail with no data #252
Comments
yeah at the moment I always check for I've made this issue in spatialwidget as that's where the fix will need to be. I'll leave this one open though until it's solved. |
Great. That's what I'm using at the moment too, along with clearing the layer when |
I've been exploring solutions to this in both the C++ (spatialwidget) side and the javascript (deck.gl) side. Deck.gl will error if it has invalid coordinates (i.e., empty data), so it may not be possible to simply pass it a |
I think the soultion is to have a check at the top of each function if( nrow( data ) == 0 ) {
return( clear_path( map, layer_id ) )
} (apart from geojson, where it has to be placed after any conversions to a data.frame) |
I don't think this will preserve legends. It's been a little while since I've looked at the deck.gl side, but if the legend is coupled with the layers, then it may be worth raising an issue with the,. As for passing |
What should the legend show, if there isn't any data on the map? If you really do want a legend without any data, you'll have to create the legend manually. I don't see another way around this as the legend is intimately tied to the data on the map. And to me it doesn't make sense to have a legend, but no data being shown.
No, I don't think so. mapdeck() %>%
add_path(
data = roads[0,]
)
# Error in rcpp_path_geojson(data, l, geometry_column, digits, "path") :
# Error creating data layer
mapdeck() %>%
add_scatterplot(
data = data.frame(lon = numeric(), lat = numeric())
, lon = "lon", lat = "lat"
)
# Error in rcpp_point_geojson_df(data, l, geometry_column, digits, "scatterplot") :
# Error creating data layer
# In addition: Warning messages:
# 1: In min(lon) : no non-missing arguments to min; returning Inf
# 2: In max(lon) : no non-missing arguments to max; returning -Inf
# 3: In min(lat) : no non-missing arguments to min; returning Inf
# 4: In max(lat) : no non-missing arguments to max; returning -Inf |
If you're animating data on the plot, and use a manually created legend to keep the values constant, I would expect the legend to remain static regardless of plotted values. AFAIK, clearing the layer will remove the legend associated with it. |
how about if the various
so then if they're false the associated calls in the |
That would work. 👍 |
yeah might be the best solution. add_arc <- function(
map,
data = get_map_data(map),
...
update_view = TRUE,
focus_layer = FALSE
) {
if( nrow( data ) == 0 ) {
return( clear_arc( map, layer_id, ... ) )
}
} |
ok, the clear_path <- function( map, layer_id = NULL, clear_legend = TRUE, clear_view = TRUE) {} and the add_path <- function(map, data, etc, ... ) {
if( nrow( data ) == 0 ) {
return( clear_path( map, layer_id, ... ) )
}
} Which for the most part works library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader()
, dashboardSidebar(
actionButton(
inputId = "clear"
, label = "clear"
)
)
, dashboardBody(
mapdeck::mapdeckOutput(
outputId = "map"
)
)
)
server <- function(input, output) {
set_token( read.dcf("~/Documents/.googleAPI", fields = "MAPBOX") )
l1 <- legend_element(
variables = c("Begins with A", "Doesn't begin with A")
, colours = c("#00FF00FF", "#FF0000FF")
, colour_type = "fill"
, variable_type = "category"
)
js <- mapdeck_legend(l1)
output$map <- mapdeck::renderMapdeck({
mapdeck() %>%
add_path(
data = roads
, stroke_colour = "ROAD_NAME"
, legend = T
)
})
observeEvent(input$clear, {
mapdeck::mapdeck_update(map_id = "map") %>%
add_path(
data = roads[0, ]
, clear_legend = FALSE
, clear_view = FALSE
)
})
}
shinyApp(ui, server) (although there is a minor bug in deck.gl where you have to have interacted with the map for it to know the current 'view state', to then know not to change the view. I'm watching this as part of #239 ) |
@mitchelloharawild could you try |
updated example: library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader()
, dashboardSidebar(
actionButton(
inputId = "clear"
, label = "clear"
)
)
, dashboardBody(
mapdeck::mapdeckOutput(
outputId = "map"
)
)
)
server <- function(input, output) {
set_token(secret::get_secret("MAPBOX"))
output$map <- mapdeck::renderMapdeck({
mapdeck() %>%
add_path(
data = roads
, stroke_colour = "ROAD_NAME"
, legend = T
)
})
observeEvent(input$clear, {
mapdeck::mapdeck_update(map_id = "map") %>%
add_path(
data = roads[0, ]
, clear_legend = FALSE
, update_view = FALSE
)
})
}
shinyApp(ui, server) |
now in master branch |
Describe the bug
An error occurs when adding a layer without data. Having no data to display can be common in interactive environments.
To Reproduce
Created on 2019-12-09 by the reprex package (v0.2.1)
Expected behaviour
The layer to be added to the plot, without any data to display.
Versions
Current dev version
TODO
The text was updated successfully, but these errors were encountered: