# load data in 'global' chunk so it can be shared by all users of the dashboard library(datasets) mtcars2 <- mtcars[, c("mpg", "cyl", "wt")]
# Reactive that returns the whole dataset if there is no brush selectedData <- reactive({ data <- brushedPoints(mtcars2, input$plot1_brush) if (nrow(data) == 0) data <- mtcars2 data })
library(ggplot2) plotOutput("plot1", brush = brushOpts(id = "plot1_brush")) output$plot1 <- renderPlot({ ggplot(mtcars2, aes(wt, mpg)) + geom_point() })
renderPlot({ ggplot(selectedData(), aes(factor(cyl), mpg)) + geom_boxplot() })
renderTable({ selectedData() })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.