Skip to content

Instantly share code, notes, and snippets.

@KKulma
Created February 12, 2019 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KKulma/e829fc18080862ef926f86ee32cb309d to your computer and use it in GitHub Desktop.
Save KKulma/e829fc18080862ef926f86ee32cb309d to your computer and use it in GitHub Desktop.
library(shiny)
library(ggplot2)
### 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")
)
server <- function(input, output) {
output$distPlot <- renderPlot({
# req('Petal.Length')
ggplot(iris, aes(Sepal.Width, Petal.Length, group = Species, color = Species)) +
geom_point() #+
#stat_smooth(method = "lm", col = "red")
})
output$dynamic <- renderUI({
req(input$plot_click)
verbatimTextOutput("vals")
})
output$vals <- renderPrint({
hover <- input$plot_click
# print(str(hover)) # list
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