dplyr-ggvis {ggvis} | R Documentation |
Applying a dplyr verb to a ggvis object creates a reactive transformation: whenever the underlying data changes the transformation will be recomputed.
## S3 method for class 'ggvis' groups(x) ## S3 method for class 'ggvis' group_by_(.data, ..., .dots, add = FALSE) ## S3 method for class 'ggvis' ungroup(x) ## S3 method for class 'ggvis' summarise_(.data, ..., .dots) ## S3 method for class 'ggvis' mutate_(.data, ..., .dots) ## S3 method for class 'ggvis' arrange_(.data, ..., .dots) ## S3 method for class 'ggvis' select_(.data, ..., .dots) ## S3 method for class 'ggvis' filter_(.data, ..., .dots) ## S3 method for class 'ggvis' distinct_(.data, ..., .dots) ## S3 method for class 'ggvis' slice_(.data, ..., .dots) ## S3 method for class 'ggvis' rename_(.data, ..., .dots) ## S3 method for class 'ggvis' transmute_(.data, ..., .dots) ## S3 method for class 'reactive' groups(x) ## S3 method for class 'reactive' ungroup(x) ## S3 method for class 'reactive' group_by_(.data, ..., .dots, add = FALSE) ## S3 method for class 'reactive' summarise_(.data, ..., .dots) ## S3 method for class 'reactive' mutate_(.data, ..., .dots) ## S3 method for class 'reactive' arrange_(.data, ..., .dots) ## S3 method for class 'reactive' select_(.data, ..., .dots) ## S3 method for class 'reactive' filter_(.data, ..., .dots) ## S3 method for class 'reactive' distinct_(.data, ..., .dots) ## S3 method for class 'reactive' slice_(.data, ..., .dots) ## S3 method for class 'reactive' rename_(.data, ..., .dots) ## S3 method for class 'reactive' transmute_(.data, ..., .dots)
Both dplyr and shiny do non-standard evaluation, so to help each package
figure out when it should evaluate its code, reactive components in
these functions must be wrapped in eval()
.
library(dplyr) base <- mtcars %>% ggvis(~mpg, ~cyl) %>% layer_points() base %>% group_by(cyl) %>% summarise(mpg = mean(mpg)) %>% layer_points(fill := "red", size := 100) base %>% filter(mpg > 25) %>% layer_points(fill := "red") base %>% mutate(cyl = jitter(cyl)) %>% layer_points(fill := "red") ## Not run: # Dynamically restrict range using filter mtcars %>% ggvis(~disp, ~mpg) %>% filter(cyl > eval(input_slider(0, 10))) %>% layer_points() # Dynamically compute box-cox transformation with mutate bc <- function(x, lambda) { if (abs(lambda) < 1e-6) log(x) else (x ^ lambda - 1) / lambda } bc_slider <- input_slider(-2, 2, 1, step = 0.1) mtcars %>% ggvis(~disp, ~mpg) %>% mutate(disp = bc(disp, eval(bc_slider))) %>% layer_points() ## End(Not run)