Last active
July 29, 2018 07:12
-
-
Save cpsievert/6fc17f4dc6d43c88dd214c12bb1a0324 to your computer and use it in GitHub Desktop.
Simple Linked Brush (modular)
This file contains 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(plotly) | |
library(shiny) | |
ui <- fluidPage( | |
fluidRow( | |
column(6, plotlyOutput("p1")), | |
column(6, plotlyOutput("p2")) | |
) | |
) | |
server <- function(input, output, session) { | |
plot_it <- function(x, y) { | |
d <- event_data("plotly_selected") | |
p <- plot_ly(mtcars, x = x, y = y) %>% | |
add_markers(key = row.names(mtcars), color = I("black")) | |
if (!is.null(d)) { | |
m <- mtcars[row.names(mtcars) %in% d[["key"]], ] | |
p <- add_markers(p, data = m, color = I("red")) | |
} | |
layout(p, dragmode = "lasso", showlegend = FALSE) | |
} | |
output$p1 <- renderPlotly({ | |
plot_it(~wt, ~mpg) | |
}) | |
output$p2 <- renderPlotly({ | |
plot_it(~wt, ~disp) | |
}) | |
} | |
shinyApp(ui, server, options = list(display.mode = "showcase")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment