I use the built-in cocaine database that comes with the ggvis package in R to visualize the amount of cocaine in each state. The R dplyr package was dplyr .
Here are the first six lines of the cocaine dataset:
state potency weight month price 1 WA 77 217 1 5000 2 CT 51 248 1 4800 3 FL 68 43 1 3500 4 OH 69 123 1 3500 5 MS 75 118 1 3400 6 VA 73 127 1 3000
The goal was to use input_select() in the ggvis package to create a drop-down menu where you could select various states and see a histogram of potency counts for that state. We managed to do this with this code:
state <- as.vector(unique(cocaine$state)) cocaine %>% ggvis(~potency) %>% filter(state == eval(input_select( choices = state, selected = "NY", label = "State"))) %>% layer_histograms(binwidth = 2)
The question is why we need the input_select() expression to be "evaluated" by eval() . Perhaps suppose filter is a function from the dplyr package and thus is not reported in the environment with ggvis ; eval therefore initializes it in ggvis environment. Perhaps someone can echo a concept that can help us visualize this?
fronk source share