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