-
-
Save dgrapov/e1712017fe6a92b48eaf to your computer and use it in GitHub Desktop.
ggvis linked brushing bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(ggvis) | |
shinyApp( | |
ui =bootstrapPage( | |
actionButton("randomize", "Randomize"), | |
ggvisOutput("plot1"), | |
ggvisOutput("plot2"), | |
verbatimTextOutput("summary") | |
), | |
server=function(input, output, session) { | |
main.data<-cocaine # staring data | |
get_data<-reactive({ | |
input$randomize # need this for data update | |
cocaine <- main.data[sample(1:nrow(main.data),20), ] | |
cocaine$id <- seq_len(nrow(cocaine)) | |
return(cocaine) | |
}) | |
observe({ | |
#new data | |
cocaine <- get_data() | |
lb <- linked_brush(keys = cocaine$id, "red") # does not reset after data update? | |
cocaine %>% | |
ggvis(~weight, ~price, key := ~id) %>% | |
layer_points(fill := lb$fill, fill.brush := "red", opacity := 0.3) %>% | |
lb$input() %>% | |
set_options(width = 300, height = 300) %>% | |
bind_shiny("plot1") # Very important! | |
# A subset of cocaine, of only the selected points | |
selected <- lb$selected | |
cocaine_selected <- reactive({ | |
input$randomize | |
cocaine[selected(), ] | |
}) | |
cocaine %>% | |
ggvis(~potency) %>% | |
layer_histograms(width = 5, boundary = 0) %>% | |
add_data(cocaine_selected) %>% | |
layer_histograms(width = 5, boundary = 0, fill := "#dd3333") %>% | |
set_options(width = 300, height = 300) %>% | |
bind_shiny("plot2") | |
#summary of selected (Selected does not react) | |
output$summary<-renderPrint({ | |
matrix(selected()) | |
}) | |
}) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment