Last active
May 31, 2017 15:49
-
-
Save seankross/f9ac7af3cc1f67c4672240f5f4e08e8c to your computer and use it in GitHub Desktop.
This file contains 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(dplyr) | |
delete_last_row <- function(df){ | |
df[1:(nrow(df) - 1),] | |
} | |
ui <- basicPage( | |
plotOutput("plot1", click = "plot_click", dblclick = "plot_dblclick") | |
) | |
server <- function(input, output) { | |
mycars <- mtcars %>% | |
select(wt, mpg) | |
output$plot1 <- renderPlot({ | |
if(!is.null(input$plot_click) && input$plot_click$x > max(mtcars$wt)){ | |
mycars <<- add_row(mycars, wt = input$plot_click$x, | |
mpg = input$plot_click$y) | |
} | |
if(!is.null(input$plot_dblclick)){ | |
mycars <<- delete_last_row(mycars) | |
} | |
plot(mycars$wt, mycars$mpg, xlim = c(1.5, 8)) | |
abline(v = max(mtcars$wt), lty = 2) | |
lines(lowess(mycars), col = 2) | |
}) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment