Created
February 12, 2019 13:36
-
-
Save KKulma/e02287b9f83715cebbd3e3f1b1441fab to your computer and use it in GitHub Desktop.
The app demonstrates how to fetch group info information from `plot_click` attribute and use it to subset a `dataTableOutput`.
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(ggplot2) | |
library(DT) | |
### The app demonstrates how to fetch group info information from `plot_click` attribute and use it to subset a `dataTableOutput`. | |
### redoing the SO answer from https://stackoverflow.com/a/38919892/6327771 (example 2) | |
ui <- fluidPage( | |
# selectInput("var_y", "Y-Axis", choices = names(iris)), | |
plotOutput("distPlot", dblclick = "plot_click"), | |
uiOutput("dynamic"), | |
dataTableOutput('table') | |
) | |
server <- function(input, output) { | |
output$table <- renderDataTable({ | |
req(input$plot_click) | |
y <- nearPoints(iris, input$plot_click)['Species'] | |
iris %>% | |
filter(Species == y$Species) | |
}) | |
output$distPlot <- renderPlot({ | |
ggplot(iris, aes(Sepal.Width, Petal.Length, group = Species, color = Species)) + | |
geom_point() | |
}) | |
output$dynamic <- renderUI({ | |
req(input$plot_click) | |
verbatimTextOutput("vals") | |
}) | |
output$vals <- renderPrint({ | |
y <- nearPoints(iris, input$plot_click)['Species'] | |
req(nrow(y) != 0) | |
y | |
}) | |
} | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment