Skip to content

Instantly share code, notes, and snippets.

@cpsievert
Last active July 29, 2018 07:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpsievert/6fc17f4dc6d43c88dd214c12bb1a0324 to your computer and use it in GitHub Desktop.
Save cpsievert/6fc17f4dc6d43c88dd214c12bb1a0324 to your computer and use it in GitHub Desktop.
Simple Linked Brush (modular)
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