Skip to content

Instantly share code, notes, and snippets.

@dillongardner
Created July 29, 2016 18:44
Show Gist options
  • Select an option

  • Save dillongardner/8073262a989816ceb919de8f8aa11f59 to your computer and use it in GitHub Desktop.

Select an option

Save dillongardner/8073262a989816ceb919de8f8aa11f59 to your computer and use it in GitHub Desktop.
library(shiny)
library(ggplot2)
ui <- basicPage(
plotOutput("plot1", brush = "plot_brush"),
actionButton("select", label="Select Data"),
actionButton("reset", label="Reset"),
verbatimTextOutput("info")
)
server <- function(input, output) {
v <- reactiveValues(data=mtcars)
isolate(v$data$selected <- FALSE)
observeEvent(input$select,{
brushedData <- brushedPoints(v$data, input$plot_brush, allRows=TRUE)
v$data$selected <- v$data$selected | brushedData$selected_
})
observeEvent(input$reset,{
v$data$selected <- FALSE
})
output$plot1 <- renderPlot({
ggplot(v$data, aes(x=wt, y=mpg,color=selected)) + geom_point()
})
output$info <- renderPrint({
v$data[v$data$selected,]
})
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment