I want to develop a shiny
app where users can draw a polygon on a raster
image. As soon as the user finishes drawing a polygon, I want the app to show them a table of chosen pixels.
For example, terra
provides a function draw
that can be used as draw("polygon")
. But, I cannot make it work with my shiny
app.
The basic idea of the app is as follows (I have commented the problematic parts with #
):
library(terra)
library(shiny)
r = rast(system.file("ex/elev.tif", package="terra"))
ui = fluidPage(
plotOutput("map"),
tableOutput("chosen_pixels")
)
server = function(input, output, session) {
output$map = renderPlot({
plot(r)
# draw("polygon") # I comment it otherwise the app does not run
})
# output$chosen_pixels = renderPlot({
# here I want to write code that shows a table of chosen pixels
#})
}
shinyApp(ui, server)