Problem with aes() when using strings and brushedPoints()

Hi - I'm reviewing this article on "Modularizing Shiny app code" Shiny - Modularizing Shiny app code and noticed that the linked to example (here: Shiny - Module example) uses older deprecated code such as using CallModule() instead of ModuleServer() and the scatterPlot() custom function uses aes_string() instead of using tidy evaluation idioms instead.

I've fixed the code to use ModuleServer() and that works fine, but when I try to fix the aes_string to call aes() instead I get an error from the brushedPoint() function:

Warning: Error in brushedPoints: brushedPoints: xvar ('.data[["cty"]]') not in names of input

The function plots fine on first call when there are no points selected with the brush, but once brushed the brushedPoints() function doesn't know how to evaluate unless I use the deprecated aes_string() function.

Does anyone know how to get this code to work without using the deprecated aes_string() function? It would be nice if the example code for the article was updated to reflect the content of the article.

Here is my modification for reference. The rest of the code is basically the same as the example except I utilized the ModuleServer() function and got rid of the CallModule() function.

scatterPlot <- function(data, cols) {
  ggplot(data, aes(x = .data[[cols[1]]], y = .data[[cols[2]]])) +
    geom_point(aes(color = selected_)) +
    scale_color_manual(values = c("black", "#66D65C"), guide = FALSE)
}

this can be considered a bug in the implementation of shiny::brushedPoints; it has simply not been implemented in away to consider the aes() to have been set using the .data pronoun.
you can continue to use aes_string() theres no actual problem with doing so if you can program what you want to program by using it.
the library(rlang) method would work also

 ggplot(data, aes(x = !!sym(cols[1]), 
                   y = !!sym(cols[2]))) 
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.