Replicate the app from the image.
Drop files here
or click to upload
library(shiny)
library(ggplot2)
ui <- fluidPage(
titlePanel("Drawing App"),
sidebarLayout(
sidebarPanel(
actionButton("clear", "Clear"),
downloadButton("save", "Save as PNG")
),
mainPanel(
plotOutput("plot", click = "plot_click"),
verbatimTextOutput("info")
)
)
)
server <- function(input, output, session) {
points <- reactiveVal(data.frame(x = numeric(0), y = numeric(0)))
output$plot <- renderPlot({
ggplot(points(), aes(x = x, y = y)) +
geom_path(size = 1, color = "black") +
theme_minimal() +
xlim(-10, 10) +
ylim(-10, 10)
})
observeEvent(input$plot_click, {
new_point <- data.frame(x = input$plot_click$x, y = input$plot_click$y)
points(rbind(points(), new_point))
})
observeEvent(input$clear, {
points(data.frame(x = numeric(0), y = numeric(0)))
})
output$save <- downloadHandler({
filename = function() { "drawing.png" },
content = function(file) {
ggsave(file, plot = output$plot())
}
})
}
shinyApp(ui = ui, server = server)
Hi! I can help you with any questions about Shiny and R. What would you like to know?