@@ -406,8 +406,6 @@ plot_with_settings_srv <- function(id,
406406 }
407407 })
408408
409-
410-
411409 plotly_brush <- reactive({
412410 req(plot_suppress(plot_r()))
413411 # layer_data(plot_r(), 3)
@@ -416,13 +414,33 @@ plot_with_settings_srv <- function(id,
416414 if (is.null(bbox )) {
417415 return (NULL )
418416 }
417+
418+ # aes() can be specified in ggplot() call or in geoms (layers)
419+ facets_mapping <- if (! is.null(plot_r()$ facet )) {
420+ facets_quo <- unlist(plot_r()$ facet $ params [c(" facets" , " rows" , " cols" )], recursive = FALSE , use.names = FALSE )
421+ unique(unlist(lapply(facets_quo , rlang :: as_label )))
422+ # todo: missing levels where brushing occurred - we don't know which facet has been brushed
423+ # although we know which datapoints x and y has been selected on the plot
424+ # we can match them with original data outside of this module... see returned $x and $y
425+ }
426+
427+ layers_mapping <- lapply(c(x = " x" , y = " y" ), function (axis ) {
428+ cols <- unique(
429+ c(
430+ rlang :: as_label(plot_r()$ mapping [[axis ]]),
431+ sapply(plot_r()$ layers , function (layer ) rlang :: as_label(layer $ mapping [[axis ]]))
432+ )
433+ )
434+ setdiff(cols , " NULL" )
435+ })
436+
419437 list (
420- mapping = list (
421- x = rlang :: as_label(plot_r()$ mapping $ x ),
422- y = rlang :: as_label(plot_r()$ mapping $ y )
423- ),
438+ mapping = layers_mapping ,
424439 xmin = min(bbox $ x ), xmax = max(bbox $ x ),
425440 ymin = min(bbox $ y ), ymax = max(bbox $ y ),
441+ facet_mapping = facets_mapping ,
442+ x = bbox $ x ,
443+ y = bbox $ y ,
426444 direction = " xy"
427445 )
428446 })
0 commit comments