Skip to content

Instantly share code, notes, and snippets.

@seankross

seankross/app.R

Last active May 31, 2017
Embed
What would you like to do?
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